An Example of Mixed Input
An Example of Mixed Input
When you begin an INPUT statement in a particular style (list, column, or formatted), you are not restricted to using that style alone. You can mix input styles in a single INPUT statement as long as you mix them in a way that appropriately describes the raw data records. For example, this DATA step uses all three input styles:
data club1; input IdNumber 1 Name $18. 2 Team $ 25-30 3 StartWeight EndWeight; 1 datalines; 1023 David Shaw 1049 Amelia Serrano 1219 Alan Nance 1246 Ravi Sinha 1078 Ashley McKnight 1221 Jim Brown ; red 189 165
yellow 220
The following list corresponds to the numbered items in the preceding program: The variables IdNumber, StartWeight, and EndWeight are read with list input. The variable Name is read with formatted input. The variable Team is read with column input. The following output demonstrates that the data is read correctly. Data Set Created with Mixed Styles of Input
Weight Club Members 1
Start Weight
End Weight
1 2 3 4 5 6
David Shaw Amelia Serrano Alan Nance Ravi Sinha Ashley McKnight Jim Brown
As the INPUT statement reads data values from the record in the input buffer, it uses a pointer to keep track of its position. Read the following sections so that you understand how the pointer movement differs between input styles before mixing multiple input styles in a single INPUT statement
The second DATA step uses the same data to show formatted input:
data scores; input Team $6. +5 Score 2.; datalines; red blue yellow green ; 59 95 63 76
The following figure shows that the pointer is located in column 7 after the first value is read with either of the two previous INPUT statements. Pointer Position: Column and Formatted Input
Unlike list input, column and formatted input rely totally on your instructions to move the pointer and read the value for the second variable, Score. Column input uses column specifications to move the pointer to each data field. Formatted input uses informats and pointer controls to control the position of the pointer. This INPUT statement uses column input with the column specifications 12-13 to move the pointer to column 12 and read the value for the variable Score:
input Team $ 1-6 Score 12-13;
This INPUT statement uses formatted input with the +5 column-pointer control to move the pointer to column 12. Then the value for the variable Score is read with the 2. numeric informat.
input Team $6. +5 Score 2.;
Without the use of a pointer control, which moves the pointer to the column where the value begins, this INPUT statement would attempt to read the value for Score in columns 7 and 8, which are blank.
The following figure shows that the pointer is located in column 5 after the value red is read. Because Score, the next variable, is read with list input, the pointer scans for the next nonblank space before it begins to read a value for Score. Unlike column and formatted input, you do not have to explicitly move the pointer to the beginning of the next field in list input. Pointer Position: List Input
You can also combine styles of input in a single INPUT statement. For details about the styles of input, see the INPUT statement in SAS Language Reference: Dictionary.
List Input
List input uses a scanning method for locating data values. Data values are not required to be aligned in columns but must be separated by at least one blank (or other defined delimiter). List input requires only that you specify the variable names and a dollar sign ($), if defining a character variable. You do not have to specify the location of the data fields. An example of list input follows:
data scores; length name $ 12; input name $ score1 score2; datalines; Riley 1132 1187 Henderson 1015 1102 ;
List input has several restrictions on the type of data that it can read:
Input values must be separated by at least one blank (the default delimiter) or by the delimiter specified with the DLM= or DLMSTR= option in the INFILE statement. If you want SAS to read consecutive delimiters as if there is a missing value between them, specify the DSD option in the INFILE statement.
Blanks cannot represent missing values. A real value, such as a period, must be used instead. To read and store a character input value longer than 8 bytes, define a variable's length by using a LENGTH, INFORMAT, or ATTRIB statement before the INPUT statement, or by using modified list input, which consists of an informat and the colon modifier in the INPUT statement. See Modified List Input for more information.
Character values cannot contain embedded blanks when the file is delimited by blanks. Fields must be read in order.
Data must be in standard numeric or character format. Note: Nonstandard numeric values, such as packed decimal data, must use the formatted style of input. See Formatted Input for more information.
The & (ampersand) format modifier enables you to read character values that contains one or more embedded blanks with list input and to specify a character informat. SAS reads until it encounters two consecutive blanks, the defined length of the variable, or the end of the input line, whichever comes first.
The : (colon) format modifier enables you to use list input but also to specify an informat after a variable name, whether character or numeric. SAS reads until it encounters a blank column, the defined length of the variable (character only), or the end of the data line, whichever comes first.
The ~ (tilde) format modifier enables you to read and retain single quotation marks, double quotation marks, and delimiters within character values. The following is an example of the : and ~ format modifiers. You must use the DSD option in the INFILE statement. Otherwise, the INPUT statement ignores the ~ format modifier.
data scores; infile datalines dsd; input Name : $9. Score1-Score3 Team ~ $25. Div $; datalines; Smith,12,22,46,"Green Hornets, Atlanta",AAA Mitchel,23,19,25,"High Volts, Portland",AAA Jones,09,17,54,"Vulcans, Las Vegas",AA ;
12 23 9
22 19 17
46 25 54
AAA AAA AA
Column Input
Column input enables you to read standard data values that are aligned in columns in the data records. Specify the variable name, followed by a dollar sign ($) if it is a character variable, and specify the columns in which the data values are located in each record:
data scores; infile datalines truncover; input name $ 1-12 score2 17-20 score1 27-30; datalines; Riley Henderson ; 1132 1015 987 1102
Note: Use the TRUNCOVER option in the INFILE statement to ensure that SAS handles data values of varying lengths appropriately. To use column input, data values must be:
in the same field on all the input lines in standard numeric or character form.
Note: You cannot use an informat with column input. Features of column input include the following:
Character values can contain embedded blanks. Character values can be from 1 to 32,767 characters long. Placeholders, such as a single period (.), are not required for missing data. Input values can be read in any order, regardless of their position in the record. Values or parts of values can be reread. Both leading and trailing blanks within the field are ignored. Values do not need to be separated by blanks or other delimiters.
Formatted Input
Formatted input combines the flexibility of using informats with many of the features of column input. By using formatted input, you can read nonstandard data for which SAS requires additional instructions. Formatted input is typically used with pointer controls that enable you to control the position of the input pointer in the input buffer when you read data. The INPUT statement in the following DATA step uses formatted input and pointer controls. Note that $12. and COMMA5. are informats and +4 and +6 are column pointer controls.
data scores; input name $12. +4 score1 comma5. +6 score2 comma5.; datalines; Riley Henderson 1,132 1,015 1,187 1,102
Note: You can also use informats to read data that is not aligned in columns. See Modified List Input for more information. Important points about formatted input are:
Characters values can contain embedded blanks. Character values can be from 1 to 32,767 characters long. Placeholders, such as a single period (.), are not required for missing data. With the use of pointer controls to position the pointer, input values can be read in any order, regardless of their positions in the record. Values or parts of values can be reread. Formatted input enables you to read data stored in nonstandard form, such as packed decimal or numbers with commas.
Named Input
You can use named input to read records in which data values are preceded by the name of the variable and an equal sign (=). The following INPUT statement reads the data lines containing equal signs.
data games; input name=$ score1= score2=; datalines; name=riley score1=1132 score2=1187 ;
Note: When an equal sign follows a variable in an INPUT statement, SAS expects that data remaining on the input line contains only named input values. You cannot switch to another form of input in the same INPUT statement after using named input.
Also, note that any variable that exists in the input data but is not defined in the INPUT statement generates a note in the SAS log indicating a missing field.
Additional Data-Reading Features Input Data Feature multiple records Goal create a single observation Use #n or / line pointer control in the INPUT statement with a DO loop. a single record create multiple observations trailing @@ in the INPUT statement. trailing @ with multiple INPUT and OUTPUT statements. variable-length data fields and records read delimited data list input with or without a format modifier in the INPUT statement and the TRUNCOVER, DLM=, DLMSTR=, or DSD options in the INFILE statement. read non-delimited data $VARYINGw. informat in the INPUT statement and the LENGTH= and TRUNCOVER options in the INFILE statement. a file with varying record layouts IF-THEN statements with multiple INPUT statements, using trailing @ or @@ as necessary. hierarchical files IF-THEN statements with multiple INPUT statements, using trailing @ as necessary. more than one input file or to control the program flow at EOF EOF= or END= option in an INFILE statement. multiple INFILE and INPUT statements. FILEVAR=option in an INFILE statement. FILENAME statement with concatenation, wildcard, or piping. only part of each record LINESIZE=option in an INFILE
statement. some but not all records in the file FIRSTOBS=and OBS= options in an INFILE statement; FIRSTOBS= and OBS= system options; #n line pointer control. instream data lines control the reading with special options INFILE statement with DATALINES and appropriate options. starting at a particular column leading blanks maintain them @ column pointer controls. $CHARw. informat in an INPUT statement. a delimiter other than blanks (with list input or modified list input with the colon modifier) DLM= or DLMSTR= option, DSD option, or both in an INFILE statement. the standard tab character DLM= or DLMSTR= option in an INFILE statement; or the EXPANDTABS option in an INFILE statement. missing values (with list input or modified list input with the colon modifier) create observations without compromising data integrity; the default behavior TRUNCOVER option in an INFILE statement; DLM= or DLMSTR= might also be needed.
For further information on data-reading features, see the INPUT and INFILE statements in SAS Language Reference: Dictionary.
INPUT Statement
Describes the arrangement of values in the input data record and assigns input values to the corresponding SAS variables.
Syntax Without Arguments Arguments Column Pointer Controls Line Pointer Controls Format Modifiers for Error Reporting Details When to Use INPUT Input Styles Column Input List Input Formatted Input Named Input Multiple Styles in a Single INPUT Statement Pointer Controls Using Column and Line Pointer Controls Using Line-Hold Specifiers Pointer Location After Reading Reading More Than One Record per Observation
Reading Past the End of a Line Positioning the Pointer Before the Record How Invalid Data is Handled End-of-File Arrays Comparisons Examples Example 1: Using Multiple Styles of Input in One INPUT Statement Example 2: Using a Null INPUT Statement Example 3: Holding a Record in the Input Buffer Example 4: Holding a Record Across Iterations of the DATA Step Example 5: Positioning the Pointer with a Numeric Variable Example 6: Positioning the Pointer with a Character Variable Example 7: Moving the Pointer Backward See Also
Syntax
INPUT <specification(s)><@|@@>;
Without Arguments
The INPUT statement with no arguments is called a null INPUT statement. The null INPUT statement
brings an input data record into the input buffer without creating any SAS variables releases an input data record that is held by a trailing @ or a double trailing @. For an example, see Using a Null INPUT Statement.
Arguments
specification(s) can include variable names a variable that is assigned input values. (variable-list) specifies a list of variables that are assigned input values. Requirement: See Also: $ specifies to store the variable value as a character value rather than as a numeric value. Tip: Featured in: pointer-control moves the input pointer to a specified line or column in the input buffer. See: Column Pointer Controls and Line Pointer Controls If the variable is previously defined as character, $ is not required. Using Multiple Styles of Input in One INPUT Statement The (variable-list) is followed by an (informat-list). How to Group Variables and Informats
column-specifications specifies the columns of the input record that contain the value to read. Tip: Informats are ignored. Only standard character and numeric data can be read correctly with this method. See: Featured in: format-modifier allows modified list input or controls the amount of information that is reported in the SAS log when an error in an input value occurs. Tip: See: Use modified list input to read data that cannot be read with simple list input. When to Use List Input Column Input Using Multiple Styles of Input in One INPUT Statement
Format Modifiers for Error Reporting Positioning the Pointer with a Character Variable
specifies an informat to use to read the variable value. Tip: You can use modified list input to read data with informats. Modified list input is useful when the data require informats but cannot be read with formatted input because the values are not aligned in columns. See: Featured in: (informat-list) specifies a list of informats to use to read the values for the preceding list of variables. Restriction: See: @ holds an input record for the execution of the next INPUT statement within the same iteration of the DATA step. This linehold specifier is called trailing @. Restriction: Tip: The trailing @ must be the last item in the INPUT statement. 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 Also: Featured in: @@ holds the 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: Tip: The double trailing @ must be the last item in the INPUT statement. The double trailing @ is useful when each input line contains values for several observations, or when a record needs to be reread on the next iteration of the DATA step. See Also: Using Line-Hold Specifiers Using Line-Hold Specifiers Holding a Record in the Input Buffer The (informat-list) must follow the (variable-list). How to Group Variables and Informats Formatted Input and List Input Using Informat Lists
Featured in:
moves the pointer to the column given by the value of numeric-variable. Range: Tip: a positive integer If numeric-variable is not an integer, SAS truncates the decimal value and only uses the integer value. If numeric-variable is zero or negative, the pointer moves to column 1. Example: The value of the variable A moves the pointer to column 15:
a=15; input @a name $10.;
moves the pointer to the column that is given by the value of expression. Restriction: Tip: Expression must result in a positive integer. If the value of expression is not an integer, SAS truncates the decimal value and only uses the integer value. If it is zero or negative, the pointer moves to column 1. Example: The result of the expression moves the pointer to column 15:
b=5; input @(b*3) name $10.;
@'character-string'
locates the specified series of characters in the input record and moves the pointer to the first column after characterstring. @character-variable locates the series of characters in the input record that is given by the value of character-variable and moves the pointer to the first column after that series of characters. Example: The following statement reads in the WEEKDAY character variable. The second @1 moves the pointer to the beginning of the input line. The value for SALES is read from the next non-blank column after the value of WEEKDAY:
input @1 day 1. @5 weekday $10. @1 @weekday sales 8.2;
locates the series of characters in the input record that is given by the value of character-expression and moves the pointer to the first column after the series. Featured in: +n moves the pointer n columns. Range: Tip: a positive integer or zero If n is not an integer, SAS truncates the decimal value and uses only the integer value. If the value is greater than the length of the input buffer, the pointer moves to column 1 of the next record. Example: This statement moves the pointer to column 23, reads a value for LENGTH from columns 23 through 26, advances the pointer five columns, and reads a value for WIDTH from columns 32 through 35:
input @23 length 4. +5 width 4.;
moves the pointer the number of columns that is given by the value of numeric-variable. Range: Tip: a positive or negative integer or zero If numeric-variable is not an integer, SAS truncates the decimal value and uses only the integer value. If numeric-variable is negative, the pointer moves backward. If the current column position becomes less than 1, the pointer moves to column 1. If the value is zero, the pointer does not move. If the value is greater than the length of the input buffer, the pointer moves to column 1 of the next record. Featured in: +(expression) Moving the Pointer Backward
moves the pointer the number of columns given by expression. Range: Tip: expression must result in a positive or negative integer or zero. If expression is not an integer, SAS truncates the decimal value and uses only the integer value. If expression is negative, the pointer moves backward. If the current column position becomes less than 1, the pointer moves to column 1. If the value is zero, the pointer does not move. If the value is greater than the length of the input buffer, the pointer moves to column 1 of the next record.
#numeric-variable moves the pointer to the record that is given by the value of numeric-variable. Range: Tip: a positive integer If the value of numeric-variable is not an integer, SAS truncates the decimal value and uses only the integer value. #(expression) moves the pointer to the record that is given by the value of expression. Range: Tip: expression must result in a positive integer. If the value of expression is not an integer, SAS truncates the decimal value and uses only the integer value. / advances the pointer to column 1 of the next input record. Example: The values for NAME and AGE are read from the first input record before the pointer moves to the second record to read the value of ID from columns 3 and 4:
input name age / id 3-4;
Details
Operating Environment Information: LOG files that are generated under z/OS and captured with PROC PRINTTO contain an ASA control character in column 1. If you are using the INPUT statement to read a LOG file that was generated under z/OS, you must account for this character if you use column input or column pointer controls.
Input Styles
There are four ways to describe a record's values in the INPUT statement:
Each variable value is read by using one of these input styles. An INPUT statement can contain any or all of the available input styles, depending on the arrangement of data values in the input records. However, once named input is used in an INPUT statement, you cannot use another input style.
Column Input
With column input, the column numbers follow the variable name in the INPUT statement. These numbers indicate where the variable values are found in the input data records:
input name $ 1-8 age 11-12;
Because NAME is a character variable, a $ appears between the variable name and column numbers. For more information, see INPUT Statement, Column.
List Input
With list input, the variable names are simply listed in the INPUT statement. A $ follows the name of each character variable:
input name $ age;
This INPUT statement can read data values that are separated by blanks or aligned in columns (with at least one blank between):
----+----1----+----2----+ Peterson Morgan 17 21
Formatted Input
With formatted input, an informat follows the variable name in the INPUT statement. The informat gives the data type and the field width of an input value. Informats also allow you to read data that are stored in nonstandard form, such as packed decimal, or numbers that contain special characters such as commas.
input name $char8. +2 income comma6.;
The pointer control of +2 moves the input pointer to the field that contains the value for the variable INCOME. For more information, see INPUT Statement, Formatted.
Named Input
With named input, you specify the name of the variable followed by an equal sign. SAS looks for a variable name and an equal sign in the input record:
input name= $ age=;
The value of IDNO, STARTWGHT, and ENDWGHT are read with list input, the value of NAME with formatted input, and the value of TEAM with column input.
Note: Once named input is used in an INPUT statement, you cannot change input styles.
Pointer Controls
As SAS reads values from the input data records into the input buffer, it keeps track of its position with a pointer. The INPUT statement provides three ways to control the movement of the pointer: column pointer controls reset the pointer's column position when the data values in the data records are read. line pointer controls reset the pointer's line position when the data values in the data records are read. line-hold specifiers hold an input record in the input buffer so that another INPUT statement can process it. By default, the INPUT statement releases the previous record and reads another record. With column and line pointer controls, you can specify an absolute line number or column number to move the pointer or you can specify a column or line location relative to the current pointer position. Pointer Controls Available in the INPUT Statement lists the pointer controls that are available with the INPUT statement. Pointer Controls Available in the INPUT Statement Pointer Controls column pointer controls Relative +n +numeric-variable +(expression) Absolute @n @numeric-variable @(expression) @'character-string' @character-variable @(character-expression) line pointer controls / #n #numeric-variable #(expression) line-hold specifiers @ @@ (not applicable) (not applicable)
Note: Always specify pointer controls before the variable to which they apply. You can use the COLUMN= and LINE= options in the INFILE statement to determine the pointer's current column and line location.
Column pointer controls indicate the column in which an input value starts. Use line pointer controls within the INPUT statement to move to the next input record or to define the number of input records per observation. Line pointer controls specify which input record to read. To read multiple data records into the input buffer, use the N= option in the INFILE statement to specify the number of records. If you omit N=, you need to take special precautions. For more information, see Reading More Than One Record per Observation.
a data record is read by more than one INPUT statement (trailing @) one input line has values for more than one observation (double trailing @) a record needs to be reread on the next iteration of the DATA step (double trailing @).
Use a single trailing @ to allow the next INPUT statement to read from the same record. Use a double trailing @ to hold a record for the next INPUT statement across iterations of the DATA step. Normally, each INPUT statement in a DATA step reads a new data record into the input buffer. When you use a trailing @, the following occurs:
The pointer position does not change. No new record is read into the input buffer. The next INPUT statement for the same iteration of the DATA step continues to read the same record rather than a new one. SAS releases a record held by a trailing @ when a null INPUT statement executes:
input;
an INPUT statement without a trailing @ executes the next iteration of the DATA step begins. Normally, when you use a double trailing @ (@@), the INPUT statement for the next iteration of the DATA step continues to read the same record. SAS releases the record that is held by a double trailing @
immediately if the pointer moves past the end of the input record immediately if a null INPUT statement executes:
input;
when the next iteration of the DATA step begins if an INPUT statement with a single trailing @ executes later in the DATA step:
input @;
REGION2 REGION3
97540 86342
This INPUT statement uses list input to read the data records:
input region $ jansales;
These INPUT statements use column and formatted input to read the data records:
column input
input region $ 1-7 jansales 12-16;
formatted input
input region $7. +4 jansales 5.; input region $7. @12 jansales 5.;
To read a value for the variable REGION, the INPUT statements instruct the pointer to read seven columns and stop in column 8.
----+----1----+----2----+----3 REGION1 49670
Unless you use N= in the associated INFILE statement, the INPUT statement reads three input records each time the DATA step executes. When each observation has multiple input records but values from the last record are not read, you must use a # pointer control in the INPUT statement or N= in the INFILE statement to specify the last input record. For example, if there are four records per observation, but only values from the first two input records are read, use this INPUT statement:
input name $ 1-10 #2 age 13-14 #4;
When you have advanced to the next record with the / pointer control, use the # pointer control in the INPUT statement or the N= option in the INFILE statement to set the number of records that are read into the input buffer. To move the pointer back to an earlier record, use a # pointer control. For example, this statement requires the #2 pointer control, unless the INFILE statement uses the N= option, to read two records:
input a / b #1 @52 c #2;
The INPUT statement assigns A a value from the first record. The pointer advances to the next input record to assign B a value. Then the pointer returns from the second record to column 1 of the first record and moves to column 52 to assign C a value. The #2 pointer control identifies two input records for each observation so that the pointer can return to the first record for the value of C. If the number of input records per observation varies, use the N= option in the INFILE statement to give the maximum number of records per observation. For more information, see the N= option.
You can alter the default behavior (the FLOWOVER option) in the INFILE statement. Use the STOPOVER option in the INFILE statement to treat this condition as an error and to stop building the data set. Use the MISSOVER option in the INFILE statement to set the remaining INPUT statement variables to missing values if the pointer reaches the end of a record. Use the TRUNCOVER option in the INFILE statement to read column input or formatted input when the last variable that is read by the INPUT statement contains varying-length data.
Therefore, SAS moves the pointer to column 1 after the value of A is read. Both variables A and B contain the same value.
sets the value of the variable that is being read to missing or the value that is specified with the INVALIDDATA= system option. For more information seeINVALIDDATA= System Option. prints an invalid data note in the SAS log. prints the input line and column number that contains the invalid value in the SAS log. Unprintable characters appear in hexadecimal. To help determine column numbers, SAS prints a rule line above the input line.
sets the automatic variable _ERROR_ to 1 for the current observation. The format modifiers for error reporting control the amount of information that is printed in the SAS log. Both the ? and ?? modifier suppress the invalid data message. However, the ?? modifier also resets the automatic variable _ERROR_ to 0. For example, these two sets of statements are equivalent:
In either case, SAS sets invalid values of X to missing values. For information about the causes of invalid data, see SAS Language Reference: Concepts.
End-of-File
End-of-file occurs when an INPUT statement reaches the end of the data. If a DATA step tries to read another record after it reaches an end-of-file then execution stops. If you want the DATA step to continue to execute, use the END= or EOF= option in the INFILE statement. Then you can write SAS program statements to detect the end-of-file, and to stop the execution of the INPUT statement but continue with the DATA step. For more information, see INFILE Statement.
Arrays
The INPUT statement can use array references to read input data values. You can use an array reference in a pointer control if it is enclosed in parentheses. SeePositioning the Pointer with a Character Variable. Use the array subscript asterisk (*) to input all elements of a previously defined explicit array. SAS allows single or multidimensional arrays. Enclose the subscript in braces, brackets, or parentheses. The form of this statement is
INPUT array-name{*};
You can use arrays with list, column, or formatted input. However, you cannot input values to an array that is defined with _TEMPORARY_ and that uses the asterisk subscript. For example, these statements create variables X1 through X100 and assign data values to the variables using the 2. informat:
array x{100}; input x{*} 2.;
Comparisons
The INPUT statement reads raw data in external files or data lines that are entered in-stream (following the DATALINES statement) that need to be described to SAS. The SET statement reads a SAS data set, which already contains descriptive information about the data values.
The INPUT statement reads data while the PUT statement writes data values, text strings, or both to the SAS log or to an external file. The INPUT statement can read data from external files; the INFILE statement points to that file and has options that control how that file is read.
Examples
Variable
Type of Input
Idno, Startwght, Endwght list input Name Team formatted input column input
To know which INPUT statement to use, check each record as it is read. Use an INPUT statement that reads only the variable that tells whether the record contains class or student.
data schedule(drop=type); infile file-specification; retain Course Professor; input type $1. @; if type='C' then input course $ professor $; else if type='S' then do; input Name $10. Id; output schedule; end; run; proc print; run;
The first INPUT statement reads the TYPE value from column 1 of every line. Because this INPUT statement ends with a trailing @, the next INPUT statement in the DATA step reads the same line. The IF-THEN statements that follow check whether the record is a class or student line before another INPUT statement reads the rest of the line. The INPUT statements without a trailing @ release the held line. The RETAIN statement saves the values about the particular college course. The DATA step writes an observation to the SCHEDULE data set after a student record is read. The following output that PROC PRINT generates shows the resulting data set SCHEDULE. Data Set Schedule
The SAS System 1
OBS
Course
Professor
Name
Id
1 2 3
The INPUT statement uses the double trailing @ to control the input pointer across iterations of the DATA step. The SAS data set contains six observations.
The first column has the column position for the office location. The next numeric column is the region category. The geographic region occurs before the number of employees in that office. You determine the office location by combining the @numeric-variable pointer control with a trailing @. To read the records, use two INPUT statements. The first INPUT statement obtains the value for the @ numeric-variable pointer control. The second INPUT statement uses this value to determine the column that the pointer moves to.
data office (drop=x); infile file-specification; input x @; if 1<=x<=10 then input @x City $9.; else do; put 'Invalid input at line ' _n_; delete; end;
run;
The DATA step writes only five observations to the OFFICE data set. The fourth input data record is invalid because the value of X is greater than 10. Therefore, the second INPUT statement does not execute. Instead, the PUT statement writes a message to the SAS log and the DELETE statement stops processing the observation.
The ARRAY statement assigns initial values to the temporary array elements. These elements correspond to the geographic regions of the office locations. The first INPUT statement uses an @character-variable pointer control. Each record is scanned for the series of characters in the value of CITY for that observation. Then the value of LOCATION is read from the next non-blank column. LOCATION is a numeric category for the geographic region of an office. The second INPUT statement uses an array reference in the @character-expression pointer control to determine the location POPULATION in the input records. The expression also uses the TRIM function to trim trailing blanks from the character value. This way an exact match is found between the character string in the input data and the value of the array element. The following output that PROC PRINT generates shows the resulting data set OFFICE2. Data Set Office2
The SAS System 1
OBS
City
Location
Population
1 2 3 4 5
1 1 1 2 4
14 2274 37 6 123
This INPUT statement uses the @ pointer control to read a value for BOOK starting at column 26. Then the pointer moves back to column 1 on the same line to read a value for COMPANY:
input @26 book $ @1 company;
These INPUT statements use +numeric-variable or +(expression) to move the pointer backward one column. These two sets of statements are equivalent.
m=-1; input x 1-10 +m y 2.;