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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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