<?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: find the bottom 20% of each by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/find-the-bottom-20-of-each-by-group/m-p/596591#M171796</link>
    <description>&lt;P&gt;Suppose there is 100 records in a group?&lt;/P&gt;</description>
    <pubDate>Tue, 15 Oct 2019 17:14:40 GMT</pubDate>
    <dc:creator>GreggB</dc:creator>
    <dc:date>2019-10-15T17:14:40Z</dc:date>
    <item>
      <title>find the bottom 20% of each by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-bottom-20-of-each-by-group/m-p/596587#M171794</link>
      <description>&lt;P&gt;&lt;U&gt;OBJECTIVE:&lt;/U&gt; Find the bottom 20% in each grade at each school based on the elavss score.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I sorted the data by school and grade and then ranked within each by group (not sure if ranking is helpful). I know that if east school has 80 students in grade 3, then I want to keep 80*20% = 16 records. Further, I know it will be the first 16 records since they are sorted low to high by elavss score.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;QUESTION:&lt;/U&gt; How do I capture those 16 records and then do the same for east school grade 4, west school grade 3, etc?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;DATA&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;school&amp;nbsp; grade elavss ela_rank&lt;/P&gt;
&lt;P&gt;east&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;east&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 121&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;east&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;200&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;east&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;222&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;west&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;west&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;105&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;west&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;143&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;west&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 167&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;west&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 189&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;&lt;U&gt;CODE&lt;/U&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=ejoin;
by school grade_level;

proc rank data=ejoin ties=low out=ela_rank;
by school grade_level;
var elavss;
ranks ela_rank;
run;

proc sort data=ela_rank;
by school grade_level ela_rank;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Oct 2019 16:58:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-bottom-20-of-each-by-group/m-p/596587#M171794</guid>
      <dc:creator>GreggB</dc:creator>
      <dc:date>2019-10-15T16:58:56Z</dc:date>
    </item>
    <item>
      <title>Re: find the bottom 20% of each by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-bottom-20-of-each-by-group/m-p/596588#M171795</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13712"&gt;@GreggB&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;U&gt;OBJECTIVE:&lt;/U&gt; Find the bottom 20% in each grade at each school based on the elavss score.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I sorted the data by school and grade and then ranked within each by group (not sure if ranking is helpful). I know that if east school has 80 students in grade 3, then I want to keep 80*20% = 16 records. Further, I know it will be the first 16 records since they are sorted low to high by elavss score.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;QUESTION:&lt;/U&gt; How do I capture those 16 records and then do the same for east school grade 4, west school grade 3, etc?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This method of counting the first 16 records ignores ties, but if that doesn't bother you, and the data is already sorted, then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by school grade_level;
    if first.grade_level then count=0;
    count+1;
    if count&amp;lt;=16 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;More generally, even if you don't know the total number of records in a group, and you want to control how to handle ties, then you could use PROC RANK with GROUPS=5, and then select the records where the rank = 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2019 17:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-bottom-20-of-each-by-group/m-p/596588#M171795</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-15T17:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: find the bottom 20% of each by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-bottom-20-of-each-by-group/m-p/596591#M171796</link>
      <description>&lt;P&gt;Suppose there is 100 records in a group?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2019 17:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-bottom-20-of-each-by-group/m-p/596591#M171796</guid>
      <dc:creator>GreggB</dc:creator>
      <dc:date>2019-10-15T17:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: find the bottom 20% of each by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-the-bottom-20-of-each-by-group/m-p/596594#M171798</link>
      <description>Add GROUPS = 5 to your PROC RANK statement to get the 20/40/60/80/100th percentiles. Take the group=0 as your lowest group.</description>
      <pubDate>Tue, 15 Oct 2019 17:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-the-bottom-20-of-each-by-group/m-p/596594#M171798</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-15T17:20:01Z</dc:date>
    </item>
  </channel>
</rss>

