Turn off ODS when running simulations in SAS


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;
%macro ODSOn(); /* Call after BY-group processing */
ods graphics on;
ods exclude none;
ods results;

For example, if I were using PROC ROBUSTREG to analyze many samples of simulated data, I might use the following pseudo-code:

proc robustreg data=MySimData;
   BY SampleID;
   model y = x;
   ods output ParameterEstimates = OutputStats;  /* <== insert name of ODS table */

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:

options nonotes;  /* use NONOTES to suppress notes to the log */
proc mixed ...;
model y = ...;
options notes;   /* turn NOTES back on */

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.


About Author

Rick Wicklin

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of SAS/IML software. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.


  1. Pingback: Simulate many samples from a logistic regression model - The DO Loop

  2. Pingback: Using simulation to estimate the power of a statistical test - The DO Loop

  3. Pingback: Monitor convergence during simulation studies in SAS - The DO Loop

  4. Pingback: Compute a bootstrap confidence interval in SAS - The DO Loop

  5. Pingback: Simulate many samples from a linear regression model - The DO Loop

    • Rick Wicklin

      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.

  6. 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?


    • Rick Wicklin

      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.

Leave A Reply

Back to Top