Using the OUTPUT Statement

The OUTPUT statement is one of those statements that in my experience does not get used too often and yet it could be used in a number of situations.  Two situations that I showcase and work through in my workshops are:

  • creating new datasets in the DATA step
  • saving results from different PROCs into a dataset that can be used later

Creating new datasets in the DATA step

In a previous post about Transposing Data you can see a great example of how one can use the OUTPUT statement while creating new datasets.

Think of the OUTPUT statement as telling SAS that you want to take the observation or data that you are currently working with and save it into a dataset.  Only catch, when you use the OUTPUT statement in the DATA step you will need to list the dataset name in the DATA step.

Data old_dataset new_dataset;
set old_dataset;
day = 1; measure = time1; output new_dataset;

Saving Results from a PROC

For this example, I’m going to work through an example that we use in the workshops again, looking at calculating Means using the PROC MEANS and saving the output results in a dataset that we can use for another analysis.

PROC MEANS is only one of many PROCs where you can save the results in a file.  The general syntax take the following format:

output  out=dataset name options;

output – lets SAS know that you will be saving the results in a datafile
out= this is where you specify the name of the datafile

options – every PROC has a different set of options that are available – these will depend on what is available to save in the file.  Options often include the ability to provide variable names.

Other PROCs that include an OUTPUT statement include:

  • many more statistical PROCedures

Screen Shot 2013-11-18 at 7.33.07 PM