SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Creating Multiple Observations from a Single Record
Reading a Varying Number of Repeating Fields


So far, each record in the file Data97 has contained the same number of repeating fields.


Raw Data File Data97
1---+----10---+----20---+----30---+----40
0734 1,323.34 2,472.85 3,276.65 5,345.52
0943 1,908.34 2,560.38 3,472.09 5,290.86
1009 2,934.12 3,308.41 4,176.18 7,581.81
1043 1,295.38 5,980.28 8,876.84 6,345.94
1190 2,189.84 5,023.57 2,794.67 4,243.35
1382 3,456.34 2,065.83 3,139.08 6,503.49
1734 2,345.83 3,423.32 1,034.43 1,942.28


But suppose that some of the employees quit after the first quarter. Records that contain information for those employees may not have sales totals for the second, third, or fourth quarter. These records contain a variable number of repeating fields.


Raw Data File Data97
1---+----10---+----20---+----30---+----40
1824 1,323.34 2,472.85
1943 1,908.34
2046 1,423.52 1,673.46 3,276.65
2063 2,345.34 2,452.45 3,523.52 2.983.01

The DATA step that you just wrote won't work with a variable number of repeating fields because now the value of Quarter is not constant for every record.

     data perm.sales97; 
        infile data97; 
        input ID $4. @;  
        do Quarter=1 to 4;
           input Sales : comma. @;
           output; 
        end;
     run;

back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement