As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


OUTPUT statement

From sasCommunity
Jump to: navigation, search
This is a work in progress. You can contribute to this article.

The OUTPUT statement is used in the DATA Step as well as in procedures. It is used to indicate where output is generated or saved.

Syntax

The syntax of the OUTPUT statement varies depending on the context in which the statement is used.

Execution

if sex='M' then output males;
In the DATA step this statement is executable. This means that the statement can be conditionally executed, such as with the IF statement.

DATA Step

All data-sets

OUTPUT ;

In a DATA Step, this variant causes the current values of the data step variables (observations) to be immediately written to all datasets specified in the DATA statement.

Named data-set

OUTPUT Dataset_name ;

In a DATA Step, this variant causes the current values of the data step variables (observations) to be immediately written to the named dataset, which needs to have been specified in the DATA statement.

Multiple data-sets

OUTPUT List of Dataset_names separated by spaces ;

In a DATA Step, this variant causes the current values of the data step variables (observations) to be immediately written to the each of the named datasets, which all need to have been specified in the DATA statement.

Procedures

The syntax in procedures can vary, depending on the procedure, although the following syntax is typical.

OUTPUT OUT= Dataset_name ;

Usage

In DATA Steps

An OUTPUT statement is not necessary in a DATA Step because one is implied at the end of each step iteration. However, if one is used then there is no implicit output at the end of the DATA Step iteration. The relevant observations are written each time an OUTPUT statement is encountered. Thus having an OUTPUT statement inside an iterative loop can result in an observation for every loop iteration.

References

  • SAS(R) 9.3 Statements: Reference: OUTPUT Statement - Versions 9.2, 9.3, 9.4