Writes variable values in the specified columns in the output line
Valid: in a DATA step
Category: File-handling
Type: Executable
PUT variable start-column < ” end-column >
<. decimal “places > <@ @@>;
variable
names the variable whose value is written.
start-column
specifies the first column of the field where the value is written in the output line.
” end-column
specifies the last column of the field for the value.
Tip: If the value occupies only one column in the output line, omit end-column .
Example: Because end-column is omitted, the values for the character variable GENDER occupy only column 16:
put name 1 10 gender 16;
.decimal-places
specifies the number of digits to the right of the decimal point in a numeric value.
Range: positive integer
Tip: If you specify 0 for d or omit d , the value is written without a decimal point.
Featured in: Examples on page 1359
@ @@
holds an output line for the execution of the next PUT statement even across iterations of the DATA step. These line-hold specifiers are called trailing @ and double trailing @ .
Requirement: The trailing @ or double trailing @ must be the last item in the PUT statement.
See: Using Line-Hold Specifiers on page 1350
With column output, the column numbers indicate the position that each variable value will occupy in the output line. If a value requires fewer columns than specified, a character variable is left-aligned in the specified columns, and a numeric variable is right-aligned in the specified columns.
There is no limit to the number of column specifications you can make in a single PUT statement. You can write anywhere in the output line, even if a value overwrites columns that were written earlier in the same statement. You can combine column output with any of the other output styles in a single PUT statement. For more information, see Using Multiple Output Styles in a Single PUT Statement on page 1348.
Use column output in the PUT statement as shown here.
This PUT statement uses column output:
data _null_; input name $ 1 18 score1 score2 score3; put name 1 20 score1 23 25 score2 28 30 score3 33 35; datalines; Joseph 11 32 76 Mitchel 13 29 82 Sue Ellen 14 27 74 ;
The program writes the following lines to the SAS log: [ *]
----+----1----+----2----+----3----+----4 Joseph 11 32 76 Mitchel 13 29 82 Sue Ellen 14 27 74
The values for the character variable NAME begin in column 1, the left boundary of the specified field (columns 1 through 20). The values for the numeric variables SCORE1 through SCORE3 appear flush with the right boundary of their field.
This statement produces the same output lines, but writes the SCORE1 value first and the NAME value last:
put score1 23 25 score2 28 30 score3 33 35 name $ 1 20;
This DATA step specifies decimal points with column output:
data _null_; x=11; y=15; put x 10 18 .1 y 20 28 .1; run;
This program writes the following line to the SAS log: [ *]
----+----1----+----2----+----3----+----4 11.0 15.0
Statement:
PUT Statement on page 1342
[ *] The ruled line is for illustrative purposes only; the PUT statement does not generate it.