In my article "Simulation in SAS: The slow way or the BY way," I showed how to use BY-group processing rather than a macro loop in order to efficiently analyze simulated data with SAS. In the example, I analyzed the simulated data by using PROC MEANS, and I use the NOPRINT option to suppress the ODS output that the procedure would normally produce.
About 50 SAS/STAT procedures support the NOPRINT option in the PROC statement. When you specify the NOPRINT option, ODS is temporarily disabled while the procedure runs. This prevents SAS from displaying tables and graphs that would otherwise be produced for each BY group. For a simulation that computes statistics for thousands of BY groups, suppressing the display of tables results in a substantial savings of time.
Newer SAS procedures do not always support a NOPRINT statement. However, you can still suppress the ODS output. The following macros encapsulate statements that turn the ODS system off and on. I call the %ODSOff macro before I start the BY-group analysis; I call the %ODSOn macro after the analysis completes.
%macro ODSOff(); /* Call prior to BY-group processing */ ods graphics off; ods exclude all; ods noresults; %mend; %macro ODSOn(); /* Call after BY-group processing */ ods graphics on; ods exclude none; ods results; %mend; |
For example, if I were using PROC ROBUSTREG to analyze many samples of simulated data, I might use the following pseudo-code:
%ODSOff proc robustreg data=MySimData; BY SampleID; model y = x; ods output ParameterEstimates = OutputStats; /* <== insert name of ODS table */ run; %ODSOn |
Even though ODS is suppressed to the display destinations (such as LISTING and HTML), you can capture the statistics that result from each analysis by using an ODS OUTPUT statement, which saves an ODS table to a SAS data set. Other ways to save statistics include using an OUTPUT statement, an OUT= or OUTEST= data set, and so forth.
Be aware that some SAS procedures (such as PROC MIXED) write a NOTE to the SAS log as part of their normal operation. The NOTE might say something like "NOTE: Convergence criteria met." For these procedures, you will also want to turn off notes, lest they fill the SAS log:
%ODSOff options nonotes; /* use NONOTES to suppress notes to the log */ proc mixed ...; model y = ...; run; options notes; /* turn NOTES back on */ %ODSOn |
The material in this blog post is taken from my book Simulating Data with SAS, which contains many more tips and techniques for the efficient simulation of data.
11 Comments
Great tips! Thanks!
Pingback: Simulate many samples from a logistic regression model - The DO Loop
Pingback: Using simulation to estimate the power of a statistical test - The DO Loop
Pingback: Monitor convergence during simulation studies in SAS - The DO Loop
Pingback: Compute a bootstrap confidence interval in SAS - The DO Loop
Pingback: Simulate many samples from a linear regression model - The DO Loop
If you use the NOPRINT option, I believe the ODS OUTPUT statement will not work.
Yes, as stated in the second paragraph. The whole point of this article is that NOPRINT turns off ODS, so if you want to use ODS OUTPUT to capture results, you need to use a different technique, such as the one I describe here.
This was helpful. Thanks.
What does the ODS NORESULTS option do on top of ODS EXCLUDE ALL/ODS SELECT NONE? Is it redundant or is there something to it that warrants its inclusion in the macro?
Is there a difference between ODS NORESULTS and ODS RESULTS OFF?
Thanks,
Haris
If you use an OUTPUT statement or an OUTEST= option, then you are correct that the ODS NORESULTS statement is not necessary. However, in many cases you use ODS EXCLUDE ALL to turn off output to the screen, but then you use an ODS OUTPUT statement to redirect certain tables to a SAS data set. The ODS NORESULT statement prevents getting thousands of entries in the results windows (treeview control) connected to creating the SAS data set for each BY group.
The ODS NORESULT statement is equivalent to ODS RESULTS OFF.