![]() Chapter Contents |
![]() Previous |
![]() Next |
| INPUT, List |
| Valid: | in a DATA step |
| Category: | File-handling |
| Type: | Executable |
Syntax |
| INPUT <pointer-control> variable <$> <&> <@ | @@>; |
|
INPUT
<pointer-control> variable <:|&|~>
<informat.> <@ | @@>; |
| See: | Column Pointer Controls and Line Pointer Controls |
| Featured in: | Reading Character Data That Contain Embedded Blanks |
| Tip: | If the variable is previously defined as character, $ is not required. |
| Featured in: | Reading Unaligned Data with Simple List Input |
| Details |
There are two types of list input:
Modified list input makes the INPUT statement more versatile because you can use a format modifier to overcome several of the restrictions of simple list input. See Modified List Input.Simple list input places several restrictions on the type of data that the INPUT statement can read:
List input is more versatile when you use format modifiers. The format modifiers are as follows:
| Format Modifier | Purpose |
|---|---|
| & | reads character values that contain embedded blanks. |
| : | reads data values that need the additional instructions that informats can provide but that are not aligned in columns. ** |
| ~ | reads delimiters within quoted character values as characters and retains the quotation marks. |
| **Use formatted input and pointer controls to quickly read data values aligned in columns. | |
Because list input interprets a blank as a delimiter, use modified list input to read values that contain blanks. The & modifier reads character values that contain single embedded blanks. However, the data values must be separated by two or more blanks. To read values that contain leading, trailing, or embedded blanks with list input, use the DELIMITER= option in the INFILE statement to specify another character as the delimiter. See Reading Delimited Data with Modified List Input. If your input data use blanks as delimiters and they contain leading, trailing, or embedded blanks, you may need to use either column input or formatted input. If quotation marks surround the delimited values, you can use list input with the DSD option in the INFILE statement.
| Comparisons |
data jansales; input item : $10. amount comma5.; datalines; trucks 1,382 vans 1,235 sedans 2,391 ;The value of ITEM is read with modified list input. The INPUT statement stops reading when the pointer finds a blank space. The pointer then moves to the second column after the end of the field, which is the correct position to read the AMOUNT value with formatted input.
input item $10. +1 amount comma5.;To read these data correctly with formatted input, the second data value must occur after the 0th column of the first value, as shown here:
----+----1----+----2 trucks 1,382 vans 1,235 sedans 2,391Also, after the value of ITEM is read with formatted input, you must use the pointer control +1 to move the pointer to the column where the value AMOUNT begins.
| Examples |
The INPUT statement in this DATA step uses simple list input to read the input data records:
data scores; input name $ score1 score2 score3 team $; datalines; Joe 11 32 76 red Mitchel 13 29 82 blue Susan 14 27 74 green ;The next INPUT statement reads only the first four fields in the previous data lines, which demonstrates that you are not required to read all the fields in the record:
input name $ score1 score2 score3;
data list; infile file-specification; input name $ & score; run;It can read these input data records:
----+----1----+----2----+----3----+ Joseph 11 Joergensen red Mitchel 13 Mc Allister blue Su Ellen 14 Fischer-Simon greenThe & modifier follows the variable it affects in the INPUT statement. Because this format modifier follows NAME, at least two blanks must separate the NAME field from the SCORE field in the input data records.
You can also specify an informat with a format modifier, as shown here:
input name $ & +3 lastname & $15. team $;In addition, this INPUT statement reads the same data to demonstrate that you are not required to read all the values in an input record. The +3 column pointer control moves the pointer past the score value in order to read the value for LASTNAME and TEAM.
This DATA step uses modified list input to read data values with an informat:
data jansales; input item : $10. amount; datalines; trucks 1382 vans 1235 sedans 2391 ;The $10. informat allows a character variable of up to ten characters to be read.
data scores2; infile datalines delimiter=','; input name $ score1-score3 team $; datalines; Joe,11,32,76,red Mitchel,13,29,82,blue Susan,14,27,74,green ;
This DATA step uses the DSD option in an INFILE statement and the tilde (~) format modifier in an INPUT statement to retain the quotation marks in character data and to read a character in a quoted string as a character instead of as a delimiter.
data scores;
infile datalines dsd;
input Name : $9. Score1-Score3
Team ~ $25. Div $;
datalines;
Joseph,11,32,76,"Red Racers, Washington",AAA
Mitchel,13,29,82,"Blue Bunnies, Richmond",AAA
Sue Ellen,14,27,74,"Green Gazelles, Atlanta",AA
;
The output that PROC PRINT generates shows the resulting SCORES data set. The values for TEAM contain the quotation marks.
The SAS System 1 OBS Name Score1 Score2 Score3 Team Div 1 Joseph 11 32 76 "Red Racers, Washington" AAA 2 Mitchel 13 29 82 "Blue Bunnies, Richmond" AAA 3 Sue Ellen 14 27 74 "Green Gazelles, Atlanta" AA |
| See Also |
Statements:
|
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.