![]() Chapter Contents |
![]() Previous |
![]() Next |
| INPUT, Formatted |
| Valid | in a DATA step |
| Category: | File-handling |
| Type: | Executable |
Syntax |
| INPUT <pointer-control> variable informat. <@ | @@>; |
|
INPUT<pointer-control>
(variable-list) (informat-list)
<@ | @@>; |
|
INPUT
<pointer-control>
(variable-list) (<n*> informat.)
<@ | @@>; |
| See: | Column Pointer Controls and Line Pointer Controls |
| Requirement: | The (variable-list) is followed by an (informat-list). |
| Featured in: | Formatted Input with Pointer Controls |
| See: | How to Group Variables and Informats |
| Featured in: | Using Informat Lists |
| Tip: | Decimal points in the actual input values override decimal specifications in a numeric informat. |
| See Also: | Informats |
| Featured in: | Formatted Input with Pointer Controls |
In the INPUT statement, (informat-list) can include
| Example: |
This statement uses
the 7.2 informat to read GRADES1, GRADES2, and GRADES3 and the 5.2 informat
to read GRADES4 and GRADES5:
input (grades1-grades5)(3*7.2, 2*5.2); |
| Restriction: | The (informat-list) must follow the (variable-list). |
| See: | How to Group Variables and Informats |
| Featured in: | Using Informat Lists |
| Details |
With formatted input, an informat follows a variable name and defines how SAS reads the values of this variable. An informat gives the data type and the field width of an input value. Informats also read data that are stored in nonstandard form, such as packed decimal, or numbers that contain special characters such as commas.(footnote 1) See Definition for descriptions of SAS informats.
Simple formatted input requires that the variables be
in the same order as their corresponding values in the input data. You can
use pointer controls to read variables in any order. For more information,
see INPUT.
By default, SAS uses the FLOWOVER option to read varying-length
data records. If the record contains fewer values than expected, the INPUT
statement reads the values from the next data record. To read varying-length
data. you may need to use the TRUNCOVER option in the INFILE statement. For more information, see
Reading Past the End of a Line.
input (score1-score5) (4. 4. 4. 4. 4.);However, if you specify more variables than informats, the INPUT statement reuses the informat list to read the remaining variables. A shorter version of the previous statement is
input (score1-score5) (4.);
data test; input (x y z) (2.,+1); datalines; 2 24 36 0 20 30 ;The +1 column pointer control moves the pointer forward one column after X is read. The value of Y is read with the 2. informat. Again, the +1 column pointer moves the pointer forward one column. Then, the value of Z is read with the 2. informat. For the third iteration, the INPUT statement ignores the +1 pointer control.
The n* modifier in an informat list specifies to repeat the next informat n times. For example,
input (name score1-score5) ($10. 5*4.);
| Comparisons |
When a variable is read with formatted input, the pointer movement is similar to that of column input. The pointer moves the length that the informat specifies and stops at the next column. To read data with informats that are not aligned in columns, use modified list input. This allows you to take advantage of the scanning feature in list input. See When to Use List Input.
| Examples |
This INPUT statement uses informats and pointer controls:
data sales;
infile file-specification;
input item $10. +5 jan comma5. +5 feb comma5.
+5 mar comma5.;
run;
It can read these input data records:
----+----1----+----2----+----3----+----4 trucks 1,382 2,789 3,556 vans 1,265 2,543 3,987 sedans 2,391 3,011 3,658The value for ITEM is read from the first 10 columns in a record. The pointer stops in column 11. The trailing blanks are discarded and the value of ITEM is written to the program data vector. Next, the pointer moves five columns to the right before the INPUT statement uses the COMMA5. informat to read the value of JAN. This informat uses five as the field width to read numeric values that contain a comma. Once again, the pointer moves five columns to the right before the INPUT statement uses the COMMA5. informat to read the values of FEB and MAR.
data scores; input (name score1-score5) ($10. 5*4.); datalines; Whittaker 121 114 137 156 142 Smythe 111 97 122 143 127 ;
| See Also |
Statements:
|
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.