Use ODS EXCLUDE ALL to suppress printing output in SAS while producing output data sets

I regularly produce output data sets from a SAS procedure, such as getting the variable names from a data set in PROC CONTENTS.  In these instances, I often wish to suppress any printing of the output in HTML or TXT.  Such printing of the results is often unnecessary, and it can cost a lot of time and memory.

Some SAS procedures have the NOPRINT option that suppresses the printing of output, but this is limiting in several ways:

  1. Some SAS procedures do NOT have the NOPRINT option.  PROC TTEST is a prominent example.  I checked the high-performance procedures like PROC HPFOREST (random forest) and PROC HPSVM (support vector machine), and I could not find the NOPRINT option for these procedures.
  2. I cannot use ODS OUTPUT to produce output data sets while invoking the NOPRINT option.  Here is an example.

proc means
     data = sashelp.class
          noprint;
     var age;
     ods output 
          summary = class_means;
run;

Running the above code will generate this message in the log.

ERROR: Neither the PRINT option nor a valid output statement has been given.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE MEANS used (Total process time):
 real time 0.01 seconds
 cpu time 0.01 seconds

WARNING: Output 'summary' was not created. Make sure that the output object name, label, or path is
 spelled correctly. Also, verify that the appropriate procedure options are used to produce
 the requested output object. For example, verify that the NOPRINT option is not used.

How can I consistently produce output data sets while suppressing the printing of output?  I learned a valuable trick from Rick Wicklin on his blog, The DO LoopIt involves ODS EXCLUDE ALL.  Here is an example with the same data set and procedure.

ods exclude all;
proc means
     data = sashelp.class;
     var age;
     ods output 
          summary = class_means;
run;
ods exclude none;

Notice that I did not use the NOPRINT option.  Instead, I used ODS EXCLUDE ALL before PROC MEANS, and I reversed its effect afterward by invoking ODS EXCLUDE NONE.

The log confirms that the data set CLASS_MEANS was created.  Let’s print it!

Obs Age_N Age_Mean Age_StdDev Age_Min Age_Max
1 19 13.315789474 1.4926721594 11 16

Not only do I suggest reading Rick’s article on different ways to suppress ODS output in SAS, but I also suggest reading his follow-up article on 5 reasons to use ODS EXCLUDE ALL to suppress output.  In this tutorial, I have shown a simple example of applying this powerful code.  However, I still recommend you to read these 2 articles to gain an in-depth understanding of this technique.

Rick has written many valuable articles on The DO Loop and on the SAS Support Communities, and I have enjoyed learning from him.  If you like SAS and statistics, then you should read his writing and follow him on Twitter.

 

Advertisements

Your thoughtful comments are much appreciated!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: