PROC MEANS - Improve on the default

From sasCommunity
Jump to: navigation, search

PROC MEANS is great for summary statistics, but is occasionally disappointing. It has some surprising conveniences. For example, did you expect to be able to create more than one output data set from just one pass?

Packaging PROC MEANS (in a macro) is sometimes very helpful. For a discussion on the topic, see SUGI 31 paper entitled "A Better Means — The ODS Data Trap", by Myra A. Oltsik and Peter Crawford.

There is a corrected and updated version of the macro %better_means().

Here is the crux of the problem. Consider this very simple invocation, driven almost entirely by defaults:

proc means data=sashelp.class noprint ;
output ;
run ;

The resulting data set, rendered by PROC PRINT, looks like this:

Obs    _TYPE_    _FREQ_    _STAT_      Age       Height     Weight

 1        0        19       N        19.0000    19.0000     19.000
 2        0        19       MIN      11.0000    51.3000     50.500
 3        0        19       MAX      16.0000    72.0000    150.000
 4        0        19       MEAN     13.3158    62.3368    100.026
 5        0        19       STD       1.4927     5.1271     22.774

Now, suppose you want to depart from the defaults by specifying a different set of statistics, but not change the design of the output data set. Surprisingly, the procedure provides no way to do that. The aforementioned macro does, though the grid is transposed so that each statistic is in a separate column and different (input) analysis variables are in different (output) rows.