DATA Step, Macro, Functions and more

Proc Means Still Can't Get Results to Follow My Custom Format

Reply
Frequent Contributor
Posts: 121

Proc Means Still Can't Get Results to Follow My Custom Format

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 ;  

Frequent Contributor
Posts: 121

Re: Proc Means Still Can't Get Results to Follow My Custom Format

Posted in reply to ManitobaMoose
"the entire data set of "ClassRanks" shows, than.."

I meant to say, the entire data set of "ClassRanks" shows, RATHER than...
Valued Guide
Posts: 525

Re: Proc Means Still Can't Get Results to Follow My Custom Format

Posted in reply to ManitobaMoose

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

Frequent Contributor
Posts: 121

Re: Proc Means Still Can't Get Results to Follow My Custom Format

Posted in reply to andreas_lds

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!

Super User
Posts: 6,644

Re: Proc Means Still Can't Get Results to Follow My Custom Format

Posted in reply to ManitobaMoose

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.

Ask a Question
Discussion stats
  • 4 replies
  • 118 views
  • 0 likes
  • 3 in conversation