DATA Step, Macro, Functions and more

How do I get a Mean of the Quartile Range?

Reply
Frequent Contributor
Posts: 130

How do I get a Mean of the Quartile Range?

Hi,

 

I am working on a problem in Learning SAS by Example. I cannot see in the book how to take the mean of the bottom half, third quartile, and top quarter. What I get now is simply a listing of the ranks from 0 100 with the mean max etc. GPA for each rank. How would I get the overall mean GPA for each of the categories? Thanks!

--------------------

/* Chapter 16
Problem 16.5*/

Libname Learn '/folders/myfolders/Learn' ;
Libname Myformat '/folders/myfolders/sasuser.v94' ;

proc format library=myformat ;
    value Rank      0-50  = 'Bottom Half'
                           51-74 = 'Third Quartile'
                           75-100  = 'Top Quarter' ;
run ;                   
        
proc means data=learn.college n mean maxdec=2 ;
    Class ClassRank ;
    Var GPA ;
    format ClassRank Rank.  ; /*DONT FORGET THIS. FOR A JUST FORMATTED FORMAT, THIS MUST BE INCLUDED*/
run ;  

 

Super User
Posts: 13,941

Re: How do I get a Mean of the Quartile Range?

Posted in reply to ManitobaMoose

Show the  code you ran from the log with any messages. Copy and paste into a code box opened using the forum {I} menu icon.

 

It sounds very much like you either did not run the Proc format step or did not include the format statement in the proc means code (or possibly both).

 

The proc format has to be run so that SAS knows what the format name is, the associated values and the desired display values are.

Then the Format statement in the procedure is used to tell SAS to display values associated with the variable using the format. In most procedures that means groups of values will be created using the levels of the format.

SAS Super FREQ
Posts: 4,274

Re: How do I get a Mean of the Quartile Range?

Posted in reply to ManitobaMoose

Your code looks fine. Is it possible that you need to run PROC RANK and analyze the output data set? Here is some working code for you to study and modify.  More more about using PROC RANK to assign ranks, see the article "Grouping observations based on quantiles"

 

proc format;
    value Rank      0-50  = 'Bottom Half'
                    51-74 = 'Third Quartile'
                    75-100  = 'Top Quarter' ;
run ;                   
   
proc rank data=sashelp.cars out=cars groups=100 ties=high;
  var mpg_city;    /* variable on which to group */
  ranks MPG_Rank;  /* name of variable to contain groups 0,1,...,k-1 */
run; 

proc means data=cars n mean maxdec=2 ;
    format MPG_Rank Rank.; 
    Class MPG_Rank ;
    Var MPG_Rank;
run ;  
Ask a Question
Discussion stats
  • 2 replies
  • 156 views
  • 0 likes
  • 3 in conversation