INPUT Statement, Formatted


Reads input values with specified informats and assigns them to the corresponding SAS variables

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. )

  • <@ @@>;

Arguments

pointer-control

  • moves the input pointer to a specified line or column in the input buffer.

  • See: Column Pointer Controls on page 1247 and Line Pointer Controls on page 1249

variable

  • names a variable that is assigned input values.

  • Requirement: The ( variable-list ) is followed by an ( informat-list ).

  • Featured in: Example 1 on page 1266

( variable-list )

  • specifies a list of variables that are assigned input values.

  • See: How to Group Variables and Informats on page 1265

  • Featured in: Example 2 on page 1266

informat.

  • specifies a SAS informat to use to read the variable values.

  • Tip: Decimal points in the actual input values override decimal specifications in a numeric informat.

  • See Also: Chapter 5, Informats, on page 927

  • Featured in: Example 1 on page 1266

( informat-list )

  • specifies a list of informats to use to read the values for the preceding list of variables In the INPUT statement, ( informat-list ) can include

  • informat.

    • specifies an informat to use to read the variable values.

  • pointer-control

    • specifies one of these pointer controls to use to position a value: @, #, /, or +.

  • n [*]

    • specifies to repeat n times the next informat in an informat list.

    • 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 on page 1265

  • Featured in: Example 2 on page 1266

@

  • holds an input record for the execution of the next INPUT statement within the same iteration of the DATA step. This line-hold specifier is called trailing @ .

  • Restriction: The trailing @ must be the last item in the INPUT statement.

  • Tip: The trailing @ prevents the next INPUT statement from automatically releasing the current input record and reading the next record into the input buffer. It is useful when you need to read from a record multiple times.

  • See: Using Line-Hold Specifiers on page 1253

@@

  • holds an input record for the execution of the next INPUT statement across iterations of the DATA step. This line-hold specifier is called double trailing @ .

  • Restriction: The double trailing @ must be the last item in the INPUT statement.

  • Tip: The double trailing @ is useful when each input line contains values for several observations.

  • See: Using Line-Hold Specifiers on page 1253

Details

When to Use Formatted Input 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. [*] See Definition of Informats on page 930 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 Statement on page 1245.

Missing Values Generally, SAS represents missing values in formatted input with a single period for a numeric value and with blanks for a character value. The informat that you use with formatted input determines how SAS interprets a blank. For example, $CHAR. w reads the blanks as part of the value, whereas BZ. w converts a blank to zero.

Reading Variable-Length Records 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 might need to use the TRUNCOVER option in the INFILE statement. For more information, see Reading Past the End of a Line on page 1232.

How to Group Variables and Informats When the input values are arranged in a pattern, you can group the informat list. A grouped informat list consists of two lists:

  • the names of the variables to read enclosed in parentheses

  • the corresponding informats separated by either blanks or commas and enclosed in parentheses.

Informat lists can make an INPUT statement shorter because the informat list is recycled until all variables are read and the numbered variable names can be used in abbreviated form. This avoids listing the individual variables.

For example, if the values for the five variables SCORE1 through SCORE5 are stored as four columns per value without intervening blanks, this INPUT statement reads the values:

 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.); 

You can use as many informat lists as necessary in an INPUT statement, but do not nest the informat lists. After all the values in the variable list are read, the INPUT statement ignores any directions that remain in the informat list. For an example, see Example 3 on page 1266.

The n * modifier in an informat list specifies to repeat the next informat n times. For example,

 input (name score1-score5) (. 5*4.); 

How to Store Informats The informats that you specify in the INPUT statement are not stored with the SAS data set. Informats that you specify with the INFORMAT or ATTRIB statement are permanently stored. Therefore, you can read a data value with a permanently stored informat in a later DATA step without having to specify the informat or use PROC FSEDIT to enter data in the correct format.

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 on page 1268.

Examples

Example 1: Formatted Input with Pointer Controls

This INPUT statement uses informats and pointer controls:

 data sales;     infile  file-specification  ;     input item . +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,658 

The 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.

Example 2: Using Informat Lists

This INPUT statement uses the character informat $10. to read the values of the variable NAME and uses the numeric informat 4. to read the values of the five variables SCORE1 through SCORE5:

 data scores;     input (name score1-score5) (. 5*4.);     datalines;  Whittaker 121 114 137 156 142  Smythe    111 97  122 143 127  ; 

Example 3: Including More Informat Specifications Than Necessary

This informat list includes more specifications than are necessary when the INPUT statement executes:

 data test;     input (x y z) (2.,+1);     datalines;  2 24 36  0 20 30     ; 

The INPUT statement reads the value of X with the 2. informat. Then, the +1 column pointer control moves the pointer forward one column. Next, 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.

See Also

Statements:

  • INPUT Statement on page 1245

  • INPUT Statement, List on page 1267

[*] See SAS Language Reference: Concepts for information on standard and nonstandard data values.




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net