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
December 2012
(for SAS and WPS)

There are a number of ways that the quantile can be calculated, but how do we find the mean, minimum and maximum for each quartile?

For this we are going to look at some golf scores for a first round at a local championship game, where we are asked to find the quartiles and then find the mean, maximum and minimum ranges for each quartile.

First our data:

   data golfscore;
      infile cards;
      input score @@;
   cards;
   66 65 73 72 89 65 64 89 68 66 69 62 87 72 72 88 83 79 66 62
   77 84 81 68 64 84 89 74 76 87 67 83 69 72 64 90 80 65 64 70
   71 78 70 79 63 71 67 86 69 74 86 78 89 79 70 73 84 64 90 63
   ;
   run;

Now we find the four quartiles by using the PROC RANK procedure, where the GROUPS=4 option will split the scores in to four groups, outputting the original data with which quartile group the score belongs in.

   proc rank data=golfscore out=golfrank groups=4;
      var score;
      ranks rank_score;
   run;

Next it is just a simple case of finding the mean, maximum and minimum scores for each quartile group by using the MEANS procedure as shown below:

   proc means data=golfrank nway mean min max;
      class rank_score;
      var score;
   run;

which results in the following output:

                          The MEANS Procedure

                       Analysis Variable : score

      Rank for
      Variable      N
         score    Obs            Mean         Minimum         Maximum
   -------------------------------------------------------------------
             0     15      64.2000000      62.0000000      66.0000000

             1     16      69.8125000      67.0000000      72.0000000

             2     15      77.8000000      73.0000000      83.0000000

             3     14      87.2857143      84.0000000      90.0000000
   -------------------------------------------------------------------

The output can be formatted a lot better than what is displayed in the default PROC MEANS, but our information is present - our lower quartile has as a mean of 64.2 and a range of 62 to 66.

Have a safe and happy December.

________________________________
Updated December 01, 2012