Reading Raw Data |
Writing the DATA Step
Program |
Describing the Data The INPUT statement describes the fields of raw data to be read and placed into the SAS data set. |
To do this... | Use this SAS statement... |
Reference SAS data library | |
Reference external file | |
Name SAS data set | data clinic.stress; |
Identify external file | infile tests obs=10; |
Describe Data | INPUT statement |
Execute the DATA step | RUN statement |
General form, INPUT statement using column input:
where
|
Take a look at the small raw data file illustrated below.
For each field of raw data that you want to read into your SAS data
set, you must assign the following in the INPUT statement:
|
Raw Data File Exercise
1---+----10---+----20 |
2810 61 MOD F |
2804 38 HIGH F |
2807 42 LOW M |
2816 26 HIGH M |
2833 32 MOD F |
2823 29 HIGH M |
The INPUT statement creates a variable using the name that you assign to each field. Therefore, when you write an INPUT statement, you need to specify the variables in the case that you want them to appear in the SAS data set. |
The INPUT statement below assigns the character variable
ID to the data in columns 1-4, the numeric variable Age
to the data in columns 6-7, the character variable ActLevel
to the data in columns 9-12, and the character variable Sex
to the data in column 14.
Notice that the variables in the data set appear in mixed case, exactly as they are specified in the INPUT statement. input ID $ 1-4 Age 6-7 ActLevel $ 9-12 Sex $ 14; |
SAS Data Set Work.Exercise
Obs | ID | Age | ActLevel | Sex |
1 | 2810 | 61 | MOD | F |
2 | 2804 | 38 | HIGH | F |
3 | 2807 | 42 | LOW | M |
4 | 2816 | 26 | HIGH | M |
5 | 2833 | 32 | MOD | F |
6 | 2823 | 29 | HIGH | M |
When you use column input, you can
input ActLevel $ 9-12 Sex $ 14 Age 6-7; |
Specifying Variable Names
Each variable has a name that conforms to SAS naming conventions. Variable names must
These are examples of valid variable names: |
|
Take a look at an INPUT statement that uses column input to read the three data fields in the raw data file below. |
1---+----10---+----20 |
58MOD M |
29LOW F |
34LOW M |
41HIGHF |
30MOD F |
22HIGHM |
The values for the variable that you're naming
Age are located in columns 1-2. Because Age is
a numeric variable, you do not specify a dollar sign ($) after the variable
name.
input Age 1-2...;
The values for the variable input Age 1-2 ActLevel $ 3-6...;
The values for the variable input Age 1-2 ActLevel $ 3-6 Sex $ 7; |
Your site may choose to restrict variables names to those valid in Version 6 SAS software, to uppercase variable names automatically, or to remove all restrictions on variable names. |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.