![]() 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*'_'; |
| 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 |
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.
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 |
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.
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 : date7.;
put 'Week of ' date : worddate15.
salesrep : $12. 'sales were '
tot : dollar9. + (-1) '.';
datalines;
Wilson 15,300 12OCT97
Hoffman 9,600 12OCT87
;
These lines appear in the SAS log:
Week of Oct 12, 1997 Wilson sales were $15,300. Week of Oct 12, 1987 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.