BookmarkSubscribeRSS Feed
ManitobaMoose
Quartz | Level 8

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 ;  

 

2 REPLIES 2
ballardw
Super User

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.

Rick_SAS
SAS Super FREQ

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 ;  

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1269 views
  • 0 likes
  • 3 in conversation