![]() Chapter Contents |
![]() Previous |
![]() Next |
| INPUT, Named |
| Valid: | in a DATA step |
| Category: | File-handling |
| Type: | Executable |
| Syntax | |
| Arguments | |
| Details | |
| When to Use Named Input | |
| Restrictions | |
| Examples | |
| Example 1: Using Named Input with Another Input Style | |
| Example 2: Reading Character Variables with Embedded Blanks | |
| See Also | |
Syntax |
| INPUT <pointer-control> variable= <$> <@ | @@>; |
| INPUT <pointer-control> variable= informat. <@ | @@>; |
|
INPUT variable= <$> start-column <-
end-column>
<.decimals> <@ | @@>; |
| See: | Column Pointer Controls and Line Pointer Controls |
variable=value
| Featured in: | Using Named Input with Another Input Style |
| Tip: | If the variable is previously defined as character, $ is not required. |
| Featured in: | Using Named Input with Another Input Style |
| Tip: | Use the INFORMAT statement to associate an informat with a variable. |
| See: | Informats |
| Featured in: | Using Named Input with Another Input Style |
| Details |
Named input reads the input data records that contain a variable name followed by an equal sign and a value for the variable. The INPUT statement reads the input data record at the current location of the input pointer. If the input data records contain data values at the start of the record that the INPUT statement cannot read with named input, use another input style to read them. However, once the INPUT statement starts to read named input, SAS expects that all the remaining values are in this form. See Using Named Input with Another Input Style.
data list; input name=$ age=; datalines; name=John age=34 gender=M ;The note written to the log states that GENDER is not defined and _ERROR_ is set to 1.
input name=$ age=;can read this input data record:
name=John / age=34
| Examples |
This DATA step uses list input and named input to read input data records:
data list; input id name=$20. gender=$; informat dob ddmmyy8.; datalines; 4798 gender=m name=COLIN age=23 dob=16/02/75 2653 name=MICHELE age=46 gender=f ;The INPUT statement uses list input to read the first variable, ID. The remaining variables NAME, GENDER, and DOB are read with named input. These variables are not read in order. The $20. informat with NAME= prevents the INPUT statement from truncating the character value to a length of eight. The INPUT statement reads the DOB= field because the INFORMAT statement refers to this variable. It skips the AGE= field altogether. SAS writes notes to the log that DOB is uninitialized, AGE is not defined, and _ERROR_ is set to 1.
This DATA step reads character variables that contain embedded blanks with named input:
data list2; informat header $30. name $15.; input header= name=; datalines; header= age=60 AND UP name=PHILIP ;Two spaces precede and follow the value of the variable HEADER, which is
AGE=60 AND UP. The field also contains an equal sign.
| See Also |
Statement:
|
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.