SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Reading Free-Format Data
Modifying List Input


Processing the DATA Step

At compile time, the informat $12. in the example below sets the length of City to 12 and stores this information in the descriptor portion of the data set. During the execution phase however, the w value of 12 does not determine the number of columns that are read. This is different from the function of informats in the formatted input style.

     data perm.cityrank;
        infile topten;
        input Rank City & $12.
              Pop86 : comma.;
     run;

1---+----10---+----20---+--
 1 NEW YORK  7,262,700 
 2 LOS ANGELES  3,259,340 
 3 CHICAGO  3,009,530 
 4 HOUSTON  1,728,910 
 5 PHILADELPHIA  1,642,900 


The & modifier indicates that the values for City should be read until two consecutive blanks are encountered. Therefore, the value NEW YORK is read from column 4 to column 11, a total of only 8 columns. When blanks are encountered in both columns 12 and 13, the value NEW YORK is written to the program data vector.

     data perm.cityrank;
        infile topten;
        input Rank City & $12.
              Pop86 : comma.;
     run;
     12345678
1---+----10V--+----20---+--
 1 NEW YORK  7,262,700 
 2 LOS ANGELES  3,259,340 
 3 CHICAGO  3,009,530 
 4 HOUSTON  1,728,910 
 5 PHILADELPHIA  1,642,900 


Program Data Vector

The input pointer moves forward to the next nonblank column, which is column 13 in the first record. Now the values for Pop86 are read from column 13 until the next blank is encountered. The COMMAw.d informat removes the commas and the value is written to the program data vector.

     data perm.cityrank;
        infile topten;
        input Rank City & $12.
              Pop86 : comma.;
     run;

 
1---+----10---+----20-V-+--
 1 NEW YORK  7,262,700 
 2 LOS ANGELES  3,259,340 
 3 CHICAGO  3,009,530 
 4 HOUSTON  1,728,910 
 5 PHILADELPHIA  1,642,900 


Program Data Vector

Notice that the character values for City and the nonstandard values for Pop86 are stored correctly in the data set.

SAS Data Set Perm.Cityrank
Rank City Pop86
1 NEW YORK 7262700
2 LOS ANGELES 3259340
3 CHICAGO 3009530
4 HOUSTON 1728910
5 PHILADELPHIA 1642900
6 DETROIT 1086220
7 SAN DIEGO 1015190
8 DALLAS 1003520
9 SAN ANTONIO 914350
10 PHOENIX 894070



back||next


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

Terms of Use & Legal Information | Privacy Statement