There's an old song that starts out, "You Can Get Anything You Want at Alice's Restaurant." Well, maybe you are too young to know that song, but if you’re a SAS users, you’ll be glad to know that you can capture anything produced by any SAS procedure (even if the procedure does not have an OUTPUT statement or does not output the values you need), with an ODS OUTPUT statement.
I used this technique in my latest book, Cody's Data Cleaning Techniques, third edition, to compute trimmed statistics using PROC UNIVARIATE. If you are not familiar with the term “trimmed statistics,” it means to compute statistics such as means and standard deviations after trimming off values from the top and bottom of a distribution. PROC UNIVARIATE has an OUTPUT statement, but it does not output a trimmed mean or trimmed standard deviation.
To determine the name of the PROC UNIVARIATE output object that contains trimmed statistics, start out by running the following:
ods trace on/listing; proc univariate data=sashelp.cars(keep=Invoice) trim=.1; *The TRIM option used here will trim 10% from the top and bottom of the distribution; var Invoice; run; ods trace off;
This places the names of the output objects directly in the output. Below is part of the output produced by this program:
Right before the reporting of trimmed statistics, you see TrimmedMeans, the name of the output object you want. The next step is to use the ODS OUTPUT statement to place the trimmed statistics in a SAS data set, like this:
ods output TrimmedMeans = Trimmed; proc univariate data=sashelp.Cars(keep=Invoice) trim=.1; *The TRIM option used here will trim 10% from the top and bottom of the distribution; var Invoice; run; ods output close;
Don't forget to close the output (just as you would close HTML or PDF). What's in data set Trimmed? Let's use PROC PRINT to find out.
title "Listing of Data Set Trimmed"; proc print data=Trimmed noobs; run;
Here is the output:
You now have your trimmed statistics in a data set. The three variables I needed from this data set were Mean (trimmed mean), StdMean (the standard error), and DF (degrees of freedom).
In summary, the ODS OUTPUT statement is a powerful tool that you can use to capture any values from any procedure and place these values in a SAS data set for further use.
Feels good to get what you want, don't you think?
For more on this topic, see the article "ODS OUTPUT: Store any statistic created by any SAS procedure"