Reading Free-Format Data | |
Using List Input |
Processing List Input
It's important to keep in mind that list input causes SAS to scan the input lines for values rather than read from specific columns. When the INPUT statement is put in the context of a DATA step and submitted for processing, the input pointer is positioned at column 1 of the raw data file, as shown below. |
data perm.survey; infile credit; input Gender $ Age Bankcard FreqBank Deptcard FreqDept; run; |
MALE
27 1 8 0 0
FEMALE
29 3 14 5 10
FEMALE
34 2 10 3 3
The first field is read until a blank space is encountered. The blank space indicates the end of the field, and the data value is assigned to the program data vector for the first variable in the INPUT statement. |
1
MALE
27 1 8 0 0
FEMALE
29 3 14 5 10
FEMALE
34 2 10 3 3
The record is scanned until the next nonblank space is found, and the second value is read until another blank is encountered. Then the value is assigned to its corresponding variable in the program data vector. |
1
MALE
27 1 8 0 0
FEMALE
29 3 14 5 10
FEMALE
34 2 10 3 3
This process of scanning ahead to the next nonblank column, reading the data value until a blank is encountered, and assigning the value to a variable in the program data vector continues until all the fields are read and values assigned to variables in the program data vector. |
When the DATA step has finished executing, you can display the data set using the PRINT procedure. The following code produces the output below. |
proc print data=perm.survey; run; |
Obs | Gender | Age | Bankcard | FreqBank | Deptcard | FreqDept |
1 | MALE | 27 | 1 | 8 | 0 | 0 |
2 | FEMALE | 29 | 3 | 14 | 5 | 10 |
3 | FEMALE | 34 | 2 | 10 | 3 | 3 |
4 | MALE | 35 | 2 | 12 | 4 | 8 |
5 | FEMALE | 36 | 4 | 16 | 3 | 7 |
6 | MALE | 21 | 1 | 5 | 0 | 0 |
7 | MALE | 25 | 2 | 9 | 2 | 1 |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.