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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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