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
|
data perm.cityrank; infile topten; input Rank City & $12. Pop86 : comma.; run; |
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 | ||||||
|
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 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
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
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.