I like Statistical Procedures in SAS. I can obtain a lot of information and output with very little coding. While this is a huge advantage of the predefined procedures in SAS, the amount of output from only a few lines of code can be quite overwhelming. Therefore you should take control over what output you actually want the procedure to output using the ODS Trace On/Off and ODS Select/Exclude statements.

ODS Trace On/Off

Last week, I blogged about Fitting Continuous Distributions to Univariate Data. I use PROC UNIVARIATE to assess the theoretical distribution that suits a variable the best. This means that I am only interested in certain parts of the default output that the Univariate Procedure produces. Before we can decide what output we want, we have to explore our options. For this purpose, wrap the procedure of interest inside ODS trace on and ODS trace off statements.

ods trace on;
proc univariate data = sashelp.cars;
   histogram mpg_city / normal;
   qqplot mpg_city / normal;
   var mpg_city;
run;
ods trace off;

SAS Log ODS Select Exclude Trace On Off

In the example above, I write a similar Univariate Procedure and wrap it inside the ODS Trace On/Off statements. This prints a list to the log of all the output parts that the procedure produces. In this example, I specifically request a Historgam and a QQ-plot. For each block of output, you see the name of the output, a label, the Template (For editing through PROC TEMPLATE), and the path in which the result is stored in the Results pathfinder.

ODS Select and ODS Exclude

The most important part of the list in the log is the name of the output. We use this name in either an ODS Select or Exclude statement to tell SAS what output to print or what output not to print. Let us assume that we are only interested in the descriptive statistics of the analysis variable mpg_city. The descriptive statistics are stored in the Moments and BasicMeasures parts of the output. Therefore we select only these two parts with an ODS Select statement like this

ods select Moments BasicMeasures;
proc univariate data = sashelp.cars;
   histogram mpg_city / normal;
   qqplot mpg_city / normal;
   var mpg_city;
run;

The Results Viewer only prints the first two blocks of output. Similarly, let us assume that the only part of the output we are definitely not interested in are the descriptive statistics part. We control this with a similar Exclude statement like this

ods exclude Moments BasicMeasures;
proc univariate data = sashelp.cars;
   histogram mpg_city / normal;
   qqplot mpg_city / normal;
   var mpg_city;
run;

Now, the only two blocks of output not written to the Results Viewer are the two first blocks, containing descriptive statistics. There are other ways to suppress output in SAS, but this one is my favorite. For more examples of the Select/Exclude statements in the Output Delivery System, consult the SAS Documentation on the subject and read Rick Wicklins article listing Five reasons to use ODS EXCLUDE to suppress SAS output

Summary

The ODS select/exclude statements are my favorite to select or suppress output in SAS. They let me control what output is relevant for my analysis and sort out the irrelevant parts. For many SAS users though, this is not the case. As an example, suppressing output is quite importing in simulation studies, as it vastly slows down your simulations. I often see SAS users use the ODS _ALL_ CLOSE statement as a way to suppress all output. While this does the job of suppressing the output, this is not a good idea.  The ODS _ALL_ CLOSE closes all open output destinations, like RTF and PDF destinations, which is not necessarily what you want. You want to control what output SAS prints, not where SAS prints it. In a future blog post, I will write about Opening And Closing Output Destinations In SAS.

For an ODS related post, see SAS ODS Style Option Example and Control Output Destination In SAS.

You can download the entire program from this post here