Skip to content
AgileLogics
6 min read

PROC MEANS and PROC SUMMARY

Prerequisites: BY-group processing

PROC MEANS computes descriptive statistics — no loops or counters needed.

Statistics per group

proc means data=sashelp.class maxdec=2;
   class sex;
   var height weight;
run;
                       The MEANS Procedure

        N
Sex   Obs   Variable    N      Mean   Std Dev   Minimum   Maximum
-------------------------------------------------------------------
F       9   Height      9     60.59      5.02     51.30     66.50
            Weight      9     90.11     19.38     50.50    112.50

M      10   Height     10     63.91      4.94     57.30     72.00
            Weight     10    108.95     22.73     83.00    150.00
-------------------------------------------------------------------
  • VAR lists the analysis variables (without it, every numeric variable is used).
  • CLASS groups the rows — no sorting needed. (BY also works, but needs sorted data and prints a separate table per group.)
  • maxdec=2 limits the decimals shown.

Choosing statistics

List statistic keywords on the PROC MEANS statement:

proc means data=sashelp.class n mean median min max maxdec=1;
   var age;
run;
              The MEANS Procedure

           Analysis Variable : Age

    N        Mean      Median     Minimum     Maximum
-----------------------------------------------------
   19        13.3        13.0        11.0        16.0
-----------------------------------------------------

Other keywords: sum, std, var, range, nmiss, q1, q3, p90, clm (confidence limits for the mean), t and probt.

Saving results with OUTPUT

PROC SUMMARY is the same procedure without printed output — it's used to create summary data sets:

proc summary data=sashelp.class nway;
   class sex;
   var height weight;
   output out=stats(drop=_type_) mean= / autoname;
run;

proc print data=stats noobs;
   format height_mean weight_mean 6.2;
run;
Sex    _FREQ_    Height_Mean    Weight_Mean

 F        9         60.59          90.11
 M       10         63.91         108.95
  • nway keeps only the rows for the full combination of CLASS variables. Without it you'd also get an overall row (_TYPE_=0).
  • _FREQ_ is the number of rows in each group.
  • mean= / autoname names the outputs variable_Mean. You can request several: output out=s mean= sum= max= / autoname;.

The result is an ordinary data set you can merge back, print, or plot.

Practice

Find the average height and weight for each age in SASHELP.CLASS, with one decimal.

Show solution
proc means data=sashelp.class mean maxdec=1;
   class age;
   var height weight;
run;

The output has one block per age from 11 to 16. For example, the two 11-year-olds average 54.4 inches and 67.8 pounds.