Writes variable values with the specified format in the output
line
| Valid: |
in a DATA step
|
| Category: |
File-handling
|
| Type: |
Executable
|
|
PUT <pointer-control> variable
format. <@ | @@>;
|
PUT <pointer-control>
(variable-list) (format-list)
<@ | @@>;
|
-
pointer-control
-
moves the output pointer to a specified
line or column.
-
variable
-
names the variable whose value is written.
-
(variable-list)
-
specifies a list of variables whose values
are written.
-
format.
-
specifies a format to use when the variable
values are written. To override the default alignment, you can add an alignment
specification to a format:
-
(format-list)
-
specifies a list of formats to use when
the values of the preceding list of variables are written. In a PUT statement,
a format-list can include
-
format.
-
specifies the format to use to write the
variable values.
-
pointer-control
-
specifies one of these pointer controls
to use to position a value: @, #, /, +, and OVERPRINT.
-
character-string
-
specifies one or more characters to place
between formatted values.
-
n*
-
specifies to repeat n times the next format in a format list.
-
@| @@
-
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 @.
The Formatted output describes the output lines by listing
the variable names and the formats to use to write the values. You can use
a SAS format or a user-written format to control how SAS prints the variable
values. For a complete description of the SAS formats, see Definition
.
With formatted output, the PUT statement uses the format
that follows the variable name to write each value. SAS does not automatically
add blanks between values. If the value uses fewer columns than specified,
character values are left-aligned and numeric values are right-aligned in
the field that is specified by the format width.
Formatted output, combined with pointer controls, makes
it possible to specify the exact line and column location to write each variable.
For example, this PUT statement uses the dollar7.2 format and centers the
value of X starting at column 12:
put @12 x dollar7.2-c;
When you want to write values in a pattern on the output
lines, use format lists to shorten your coding time. A format list consists
of the corresponding formats separated by either blanks or commas and enclosed
in parentheses. It must follow the names of the variables enclosed in parentheses.
For example, this statement uses a format list to write
the five variables SCORE1 through SCORE5, one after another, using four columns
for each value with no blanks in between:
put (score1-score5) (4. 4. 4. 4. 4.);
A shorter version of the previous statement is
put (score1-score5) (4.);
You can include any of the pointer controls (@, #, /,
+, and OVERPRINT) in the list of formats, as well as n*, and a character string. You can use as many format
lists as necessary in a PUT statement, but do not nest the format lists. After
all the values in the variable list are written, the PUT statement ignores
any directions that remain in the format list.
For example, this format list includes more specifications
than are necessary when the PUT statement writes the last variable:
data _null_;
input x y z;
put (x y z) (2.,+1);
datalines;
2 24 36
0 20 30
;
The PUT statement writes the value of X using the 2. format. Then,
the +1 column pointer control moves the pointer forward one column. Next,
the value of Y is written with the 2. format. Again, the +1 column pointer
moves the pointer forward one column. Then, the value of Z is written with
the 2. format. For the third iteration, the PUT statement ignores the +1
pointer control.
These lines are written to the SAS log:(footnote 1)
----+----1----+
2 24 36
0 20 30
You can also specify a reference to all elements in
an array as (array-name {*}), followed
by a list of formats. You cannot, however, specify the elements in a _TEMPORARY_
array in this way. This PUT statement specifies an array name and a format
list:
put (array1{*}) (4.);
For more information on how
to reference an array, see Arrays.
This example formats some values and writes a - (hyphen)
between the values of variables BLDG and ROOM:
data _null_;
input name & $15. bldg $ room;
put name @20 (bldg room) ($1. "-" 3.);
datalines;
Bill Perkins J 126
Sydney Riley C 219
;
These lines are written to the SAS log:
Bill Perkins J-126
Sydney Riley C-219
This example includes an alignment specification in
the format:
data _null_;
input name $ 1-12 score1 score2 score3;
put name $12.-r +3 score1 3. score2 3.
score3 4.;
datalines;
Joseph 11 32 76
Mitchel 13 29 82
Sue Ellen 14 27 74
;
These lines are written to the log:
----+----1----+----2----+----3----+----4
Joseph 11 32 76
Mitchel 13 29 82
Sue Ellen 14 27 74The value of the character variable NAME is
right-aligned in the formatted field. (Left alignment is the default for character
variables.)
FOOTNOTE 1:
The ruled line is for illustrative purposes only; the
PUT statement does not generate it.
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.