<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Proc Means Still Can't Get Results to Follow My Custom Format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Means-Still-Can-t-Get-Results-to-Follow-My-Custom-Format/m-p/434433#M107804</link>
    <description>&lt;P&gt;I think you need to be using QuartileRanks in CLASS statement in PROC MEANS.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Feb 2018 00:53:00 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-02-06T00:53:00Z</dc:date>
    <item>
      <title>Proc Means Still Can't Get Results to Follow My Custom Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Means-Still-Can-t-Get-Results-to-Follow-My-Custom-Format/m-p/434426#M107800</link>
      <description>&lt;P&gt;Ok, let me try this one last time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to sort the data into lower half, third quartile, and top quartile. However, I can't get this to work. The output shows all the data listed from a ClassRank of 41 to 100, with the GPA for each ClassRank. What I want is to divide the 60 observations into groups 41-60, 61-80, and 81-100, with the average GPA shown for each group. How would I do this?&lt;/P&gt;&lt;P&gt;Below is my attempted way of doing this. At the bottom is the code for the dataset learn.college. Note that this is not a real data set, but a problem from an instructional book. Therefore, the ClassRank and GPA does not necessarily make sense in normal terms... i.e. a GPA of 4 would have a Lower ClassRank than someone with a GPA of 3.3. The data itself doesn't matter. How to organize the data into thirds with the average GPA calculated for each third is what matters. Thanks a lot!&lt;/P&gt;&lt;P&gt;---------------------------&lt;/P&gt;&lt;P&gt;Libname Learn '/folders/myfolders/Learn' ;&lt;BR /&gt;Libname Myformat '/folders/myfolders/sasuser.v94' ;&lt;BR /&gt;&lt;BR /&gt;proc format library=myformat ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value Rank&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 41-60&amp;nbsp; = 'Bottom Third''&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 61-81 = 'Middle Third'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 81-100&amp;nbsp; = 'Top Third'' ;&lt;BR /&gt;run ;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;/* %let NumGroups= 4 ;&lt;BR /&gt;proc rank data=learn.college Groups=&amp;amp;NumGroups ties=high ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;var ClassRank ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Ranks QuartileRank ;&lt;BR /&gt;run ; */&lt;BR /&gt;&lt;BR /&gt;proc means data=learn.college noprint nway;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Class ClassRank ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Var GPA ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Output Out=ClassRankSpecial ;&lt;BR /&gt;run ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;proc means data=ClassRankSpecial n mean maxdec=2 ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Class ClassRank ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Var GPA ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;format ClassRank Rank.&amp;nbsp; ; /*DONT FORGET THIS. FOR A JUST FORMATTED FORMAT, THIS MUST BE INCLUDED*/&lt;BR /&gt;run ;&lt;/P&gt;&lt;P&gt;------------------------&lt;/P&gt;&lt;P&gt;BELOW IS THE DATASET LEARN.COLLEGE:&lt;/P&gt;&lt;P&gt;------------------------&lt;/P&gt;&lt;P&gt;data learn.college;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; length StudentID $ 5 Gender SchoolSize $ 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; do i = 1 to 100;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; StudentID = put(round(ranuni(123456)*10000),z5.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ranuni(0) lt .4 then Gender = 'M';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else Gender = 'F';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ranuni(0) lt .3 then SchoolSize = 'S';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if ranuni(0) lt .7 then SchoolSize = 'M';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else SchoolSize = 'L';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ranuni(0) lt .2 then Scholarship = 'Y';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else Scholarship = 'N';&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GPA = round(rannor(0)*.5 + 3.5,.01);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if GPA gt 4 then GPA = 4;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ClassRank = int(ranuni(0)*60 + 41);&amp;nbsp; /* the + 41 is there because of missing data (my note) */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ranuni(0) lt .1 then call missing(ClassRank);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ranuni(0) lt .05 then call missing(SchoolSize);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ranuni(0) lt .05 then call missing(GPA);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; format Gender $gender1.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SchoolSize $size.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Scholarship $yesno.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; drop i;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 00:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Means-Still-Can-t-Get-Results-to-Follow-My-Custom-Format/m-p/434426#M107800</guid>
      <dc:creator>ManitobaMoose</dc:creator>
      <dc:date>2018-02-06T00:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Means Still Can't Get Results to Follow My Custom Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Means-Still-Can-t-Get-Results-to-Follow-My-Custom-Format/m-p/434431#M107803</link>
      <description>&lt;P&gt;Since we do not have your data you should 1) provide example input data, 2) the expected or desired output. A data set created with random values for variables means that we do &lt;U&gt;&lt;STRONG&gt;not&lt;/STRONG&gt;&lt;/U&gt; have the same data, can practically never get the same result and have no idea if we are getting the desired result or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It does not help to provide code with libraries we don't have (library)&amp;nbsp;or formats without definitions (gender1, size yesno&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that your rank assignment creates many duplicates with gaps so is problematic at best, especially given 100 students...&lt;/P&gt;
&lt;PRE&gt;data work.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;
      if ranuni(0) lt .05 then call missing(SchoolSize);
      if ranuni(0) lt .05 then call missing(GPA);
      output;
   end;
   drop i;
run;

proc rank data=work.college Groups=100 ties=high 
     out= work.ranked;
    var gpa ;
    Ranks PercentileRank ;
run ; 
proc format library=work ;
value Rank       
   41-60  = 'Bottom Third'
   61-81  = 'Middle Third'
   81-100 = 'Top Third' ;
run ;   

Proc summary data=work.ranked nway ;
   where percentilerank ge 41;
   class percentilerank; 
   var gpa;
   output out=work.classrankspecial mean=;
   format percentilerank rank.; 
run;

/* or */

proc tabulate data=work.ranked;
   where percentilerank ge 41;
   class percentilerank; 
   var gpa;
   table percentilerank='',
         gpa*mean='';
   format percentilerank rank.; 
run;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Feb 2018 00:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Means-Still-Can-t-Get-Results-to-Follow-My-Custom-Format/m-p/434431#M107803</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-06T00:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Means Still Can't Get Results to Follow My Custom Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Means-Still-Can-t-Get-Results-to-Follow-My-Custom-Format/m-p/434433#M107804</link>
      <description>&lt;P&gt;I think you need to be using QuartileRanks in CLASS statement in PROC MEANS.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 00:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Means-Still-Can-t-Get-Results-to-Follow-My-Custom-Format/m-p/434433#M107804</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-06T00:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Means Still Can't Get Results to Follow My Custom Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Means-Still-Can-t-Get-Results-to-Follow-My-Custom-Format/m-p/434438#M107806</link>
      <description>&lt;P&gt;What is the purpose of running PROC MEANS twice?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just want to work on LEARN.COLLEGE, you can run PROC MEANS once on that data set.&amp;nbsp; Use the syntax of your second PROC MEANS, but change the input data set to be LEARN.COLLEGE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The way the program appears now, it looks like you want an average of averages.&amp;nbsp; First average all the students with RANK=41, RANK=42, RANK=43, etc.&amp;nbsp; Then take those averages and re-average them within your groupings.&amp;nbsp; If that is your intent, you should add to the OUTPUT statement on the first PROC MEANS:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Output Out=ClassRankSpecial mean=;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can see what I'm talking about by examining ClassRankSpecial using the current program, vs. using the modified OUTPUT statement.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 01:32:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Means-Still-Can-t-Get-Results-to-Follow-My-Custom-Format/m-p/434438#M107806</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-06T01:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Means Still Can't Get Results to Follow My Custom Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Means-Still-Can-t-Get-Results-to-Follow-My-Custom-Format/m-p/434446#M107811</link>
      <description>&lt;P&gt;I don't know what you're looking for in the output but this works fine for me. I think you're possibly running into trouble with the Formats and where it's stored and where its searching.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

proc format ;
    value Rank       41-60  = 'Bottom Third'
                           61-81 = 'Middle Third'
                           81-100  = 'Top Third' ;
run ; 

data 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 classrank rank.;
   drop i;
run;


         
proc means data=college n mean maxdec=2 nway ;
    class ClassRank;
    Var GPA ;
    *format ClassRank Rank.  ; /*DONT FORGET THIS. FOR A JUST FORMATTED FORMAT, THIS MUST BE INCLUDED*/
/*NOPE, IT CAN BE ASSIGNED AHEAD OF TIME, IT DOESNT NEED TO BE INCLUDED IN THE PROC MEANS*/

output out=want n= mean= / autoname;
run ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Feb 2018 02:11:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Means-Still-Can-t-Get-Results-to-Follow-My-Custom-Format/m-p/434446#M107811</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-06T02:11:46Z</dc:date>
    </item>
  </channel>
</rss>

