Chapter Contents

Previous

Next
PUT, List

PUT, List



Writes variable values and the specified character strings in the output line

Valid: in a DATA step
Category: File-handling
Type: Executable


Syntax
Arguments
Details
Using List Output
How List Output is Spaced
Comparisons
How Modified List Output and Formatted Output Differ
Examples
Example 1: Writing Values with List Output
Example 2: Writing Character Strings and Variable Values
Example 3: Writing Values with Modified List Output
See Also

Syntax

PUT <pointer-control> variable <@ | @@>;
PUT <pointer-control> <n*>'character-string'
<@ | @@>;
PUT <pointer-control> variable : format.<@ | @@>;

Arguments

pointer-control
moves the output pointer to a specified line or column.
See: Column Pointer Controls and Line Pointer Controls
Featured in: Writing Character Strings and Variable Values

variable
names the variable whose value is written.
Featured in: Writing Values with List Output

n*
specifies to repeat n times the subsequent character string.
Example: This statement writes a line of 132 underscores:
put 132*'_';

'character-string'
specifies a string of text, enclosed in quotation marks, to write.
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

:
allows you to specifiy a format that the PUT statement uses to write the variable value. All leading and trailing blanks are still deleted, and each value is followed by a single blank.
Requirement: You must specify a format.
See: How Modified List Output and Formatted Output Differ
Featured in: Writing Values with Modified List Output

format.
specifies a format to use when the data values are written.
Tip: You can specify either a SAS format or a user-written format. See Formats.
Featured in: Writing Values with Modified List Output

@ | @@
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 @.
Restriction: The trailing @ or double-trailing @ must be the last item in the PUT statement.
See: Using Line-hold Specifiers


Details

Using List Output

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.

How List Output is Spaced

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

How Modified List Output and Formatted Output Differ

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

Example 1: Writing Values with List Output

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 11
By default, the values of the character variable NAME are left-aligned in the field.

Example 2: Writing Character Strings and Variable Values

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.

Example 3: Writing Values with Modified List Output

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:
PUT
PUT, Formatted


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.