Control your Output with ODS select/exclude
One of the things I like the most about doing analysis and statistics using SAS procedures is that I can obtain a lot of knowledge 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 used PROC UNIVARIATE to assess the theoretical distribution that suits some 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;
In the example above, I have written a similar Univariate Procedure and wrapped it inside the ODS trace on/off statements. This prints a list to the log of all the output parts that the procedure produces, either by default or by request. 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 shortly explaining it, the Template (For editing through PROC TEMPLATE eg) and the path in which the result is stored in the Results pathfinder.
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 part 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;
Only the two first blocks of output, that contains descriptive statistics are outputted to the Results Viewer. Similarly, let us assume that the only part of the output we are definitely NOT interested in are the descriptive statistics part. This can be done 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
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.
You can download the entire program from this post here