College of Natural Sciences
 
FAQs
This is for IE7 to hold div open

SAS FAQ #34: Reading hierarchical raw data files

Question:

How do I read data into a SAS dataset when the data in one variable indicates which variables should be read in next (from the same line)?

Answer:

From the same line depending on the decisive variable's value, use a trailing at-sign @ in the SAS INPUT statement. For example:

INPUT a 7 @;
IF a = 1 THEN INPUT b 9-13 c 15;
IF a = 2 THEN INPUT d 16 e 17-18;

Here the variable A is read from column 7. If its value is 1, then variables B and C are read. If A's value is 2, then variables D and E are read. If A's value is anything other than 1 or 2, no other variables are read.

The critical component is the trailing single @ in the initial INPUT statement. This holds the pointer (the device that is reading the data file) at its present location (the first blank after the variable A), so that data can continue to be read in from the current line when another INPUT statement is processed. Removing the @ would cause the pointer to read from the next line of data each time the INPUT command is encountered.

For more information, click on the Help button in the SAS menu bar and scroll to SAS Help and Documentation.

If you have further questions, send E-mail to stats@ssc.utexas.edu.