Return to Archive

SAS Tip of the Month
November 2003

Here is an oldie, but a good example of SAS code that I find useful.

Using the following data find the Number of Observations, Mean, Standard Deviation, Median, Minimum and Maximum values for the following data, grouping by Gender and age groups 18-64 and 65-75:


   ** DATA **
   SUBJECT  AGE  GENDER
     001     35    M
     002     70    M
     003     65    M
     004     40    F
     005     66    F
     006     36    F

   ** SAS PROGRAM **
   PROC FORMAT;
      VALUE agex
        18-64='18-64'
        65-75='65-75'
        other='Unexpected';
   RUN;
   PROC MEANS DATA=demog N MEAN STD MEDIAN MIN MAX;
      CLASS gender age;
      VAR age;
      FORMAT age agex.;
   RUN;

Using the AGE variable both in the CLASS and VAR statements it is treated both as a category and analysis variable. Note that the median calculation came into the MEANS procedure in SAS version 7 - prior to that the median could be calculated using the UNIVARIATE procedure.

________________________________
Updated November 13, 2003