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.

## 6 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