BookmarkSubscribeRSS Feed
ManitobaMoose
Quartz | Level 8

Hi,

 

I am trying to get a specific format, but no matter what I do, the entire data set of "ClassRanks" shows, than the means for the groups that are Bottom Half, Third quartile, or Top Quarter. Not sure what to do. Maybe someone on here can help. Thanks!

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

 

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 noprint ;
    Class ClassRank ;
    Var GPA ;
    Output Out=ClassRankSpecial ;
run ;
   
proc means data=ClassRankSpecial n mean maxdec=2 ;
    Class ClassRank ;
    Var GPA ;
    format ClassRank Rank.  ;
run ;  

4 REPLIES 4
ManitobaMoose
Quartz | Level 8
"the entire data set of "ClassRanks" shows, than.."

I meant to say, the entire data set of "ClassRanks" shows, RATHER than...
andreas_lds
Jade | Level 19

I don't have access to the data you used, can you post some lines of learn.college and what you expect as output?

ManitobaMoose
Quartz | Level 8

Here is the text from the learn.college data set. It actually goes from 41-100.

 

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

data learn.college;
   length StudentID $ 5 Gender SchoolSize $ 1;
   do i = 1 to 100;
      StudentID = put(round(ranuni(123456)*10000),z5.);
      if ranuni(0) lt .4 then Gender = 'M';
      else Gender = 'F';
      if ranuni(0) lt .3 then SchoolSize = 'S';
      else if ranuni(0) lt .7 then SchoolSize = 'M';
      else SchoolSize = 'L';
      if ranuni(0) lt .2 then Scholarship = 'Y';
      else Scholarship = 'N';
      GPA = round(rannor(0)*.5 + 3.5,.01);
      if GPA gt 4 then GPA = 4;
      ClassRank = int(ranuni(0)*60 + 41);  /* the + 41 is there because of missing data (my note) */
      if ranuni(0) lt .1 then call missing(ClassRank);
      if ranuni(0) lt .05 then call missing(SchoolSize);
      if ranuni(0) lt .05 then call missing(GPA);
      output;
   end;
   format Gender $gender1.
          SchoolSize $size.
          Scholarship $yesno.;
   drop i;
run;

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

Thanks!

Astounding
PROC Star

Two items to address ...

 

First (if not already done), validate that the values for ClassRank actually range from 0 to 100.

 

Second, add NWAY to the end of the first PROC MEANS statement:

 

proc means data=learn.college noprint  nway;

 

Without it, the output data set contains an extra observation with statistics for the entire data set.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 745 views
  • 0 likes
  • 3 in conversation