Chapter Contents |
Previous |
Next |
PUT, List |
Valid: | in a DATA step |
Category: | File-handling |
Type: | Executable |
Syntax |
PUT <pointer-control> variable <@ | @@>; |
PUT <pointer-control>
<n*>'character-string'
<@ | @@>; |
PUT <pointer-control> variable : format.<@ | @@>; |
See: | Column Pointer Controls and Line Pointer Controls |
Featured in: | Writing Character Strings and Variable Values |
Featured in: | Writing Values with List Output |
Example: | This statement writes
a line of 132 underscores:
put 132*'_'; |
Interaction: | When insufficient space remains on the current line to write the entire text string, SAS withholds the entire string and writes the current line. Then it writes the text string on a new line, starting in column 1. For more information, see When the Pointer Goes Past the End of a Line. |
Tip: | To avoid misinterpretation, always put a space after a closing quotation mark in a PUT statement. |
Tip: | If you follow a quotation mark with X, SAS interprets the text string as a hexadecimal constant. |
See Also: | How List Output is Spaced |
Featured in: | Writing Character Strings and Variable Values |
Requirement: | You must specify a format. |
See: | How Modified List Output and Formatted Output Differ |
Featured in: | Writing Values with Modified List Output |
Tip: | You can specify either a SAS format or a user-written format. See Formats. |
Featured in: | Writing Values with Modified List Output |
Restriction: | The trailing @ or double-trailing @ must be the last item in the PUT statement. |
See: | Using Line-hold Specifiers |
Details |
With list output, you list the names of the variables whose values you want written, or you specify a character string in quotation marks. The PUT statement writes a variable value, inserts a single blank, and then writes the next value. Missing values for numeric variables are written as a single period. Character values are left-aligned in the field; leading and trailing blanks are removed. To include blanks (in addition to the blank inserted after each value), use formatted or column output instead of list output.
There are two types of list output:
Modified list output increases the versatility of the
PUT statement because you can specify a format to control how the variable
values are written. See Writing Values with Modified List Output.
List output uses different spacing methods when it writes variable values and character strings. When a variable is written with list output, SAS automatically inserts a blank space. The output pointer stops at the second column that follows the variable value. However, when a character string is written, SAS does not automatically insert a blank space. The output pointer stops at the column that immediately follows the last character in the string.
To avoid spacing problems when both character strings and variable values are written, you may want to use a blank space as the last character in a character string. When a character string that provides punctuation follows a variable value, you need to move the output pointer backward. This prevents an unwanted space from appearing in the output line. See Writing Character Strings and Variable Values.
Comparisons |
List output and formatted output use different methods to determine how far to move the pointer after a variable value is written. Therefore, modified list output, which uses formats, and formatted output produce different results in the output lines. Modified list output writes the value, inserts a blank space, and moves the pointer to the next column. Formatted output moves the pointer the length of the format, even if the value does not fill that length. The pointer moves to the next column; an intervening blank is not inserted.
The following DATA step uses modified list output to write each output line:
data _null_; input x y; put x : comma10.2 y : 7.2; datalines; 2353.20 7.10 6231 121 ;
These lines are written to the SAS log:
----+----1----+----2 2,353.20 7.10 6,231.00 121.00
In comparison, the following example uses formatted output:
put x comma10.2 y 7.2;
These lines are written to the SAS log, with the values aligned in columns:
----+----1----+----2 12,353.20 7.10 6,231.00 121.00
Examples |
This DATA step uses a PUT statement with list output to write variable values to the SAS log:
data _null_; input name $ 1-10 sex $ 12 age 15-16; put name sex age; datalines; Joseph M 13 Mitchel M 14 Sue Ellen F 11 ;
These lines are written to the log:
----+----1----+----2----+----3----+----4 Joseph M 13 Mitchel M 14 Sue Ellen F 11By default, the values of the character variable NAME are left-aligned in the field.
This PUT statement adds a space to the end of a character string and moves the output pointer backward to prevent an unwanted space from appearing in the output line after the variable STARTWGHT:
data _null_; input idno name $ startwght; put name 'weighs ' startwght +(-1) '.'; datalines; 032 David 180 049 Amelia 145 219 Alan 210 ;
These lines are written to the SAS log:
David weighs 180. Amelia weighs 145. Alan weighs 210.The blank space at the end of the character string changes the pointer position. This space separates the character string from the value of the variable that follows. The +(-1) pointer control moves the pointer backward to remove the unwanted blank that occurs between the value of STARTWGHT and the period.
This DATA step uses modified list output to write several variable values in the output line:
data _null_; input salesrep : $10. tot : comma6. date : date9.; put 'Week of ' date : worddate15. salesrep : $12. 'sales were ' tot : dollar9. + (-1) '.'; datalines; Wilson 15,300 12OCT1999 Hoffman 9,600 12OCT1999 ;
These lines appear in the SAS log:
Week of Oct 12, 1999 Wilson sales were $15,300. Week of Oct 12, 1999 Hoffman sales were $9,600.
See Also |
Statements:
|
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.