ƒ David Franklin, SAS Programmer - SAS Tip of the Month, May 2015

Return to Homepage

Goto the Tip of the Month Archive

Other interesting pages ...
LinkedIn Profile
SAS Cheat Sheet
Useful SAS Code
Full SAS Example
Basic Statistics
Contact Information

SAS Tip of the Month
May 2015
(for SAS)

In SAS we can group results using formats as given in the example below:

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.

Hope this was useful.

________________________________
Updated May 2, 2015