<?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: Extracting top 20 - 30 observations group wise from SAS dataset in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Extracting-top-20-30-observations-group-wise-from-SAS-dataset/m-p/278357#M14686</link>
    <description>&lt;P&gt;There is some sample code in SAS &lt;A href="http://support.sas.com/kb/24/778.html" target="_blank"&gt;note 24778&lt;/A&gt; that explains how to do it in datastep. Depending on how you'd like to deal with ties (equal scores) PROC RANK may also be helpful:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.cars out=cars;
        by make;
run;
proc rank data=sashelp.cars ou=carsrank;
        by make;
        var horsepower;
        ranks hp_r;
run;
proc sort data=carsrank;
        by make hp_r;
        where hp_r &amp;lt;= 5;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Actually, Google on "sas top n by group" gives a myriad of alternatives, each with its own virtues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
    <pubDate>Sat, 18 Jun 2016 10:49:33 GMT</pubDate>
    <dc:creator>jklaverstijn</dc:creator>
    <dc:date>2016-06-18T10:49:33Z</dc:date>
    <item>
      <title>Extracting top 20 - 30 observations group wise from SAS dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Extracting-top-20-30-observations-group-wise-from-SAS-dataset/m-p/278351#M14685</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've been struggling to figure out a way to extract the top 20-30 observations, group wise, from a SAS dataset I'm working &amp;nbsp;on.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, I have 5 Indian cities in my dataset (Variable = City) and Net sales against each customer name. I want to pull out the top 20 - 30 observations&amp;nbsp;based on the largest net sales values for each city automatically and subsequently create a separate dataset of those observations. Can someone help me here please? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jun 2016 10:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Extracting-top-20-30-observations-group-wise-from-SAS-dataset/m-p/278351#M14685</guid>
      <dc:creator>AkshayjitSinghNarula</dc:creator>
      <dc:date>2016-06-18T10:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting top 20 - 30 observations group wise from SAS dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Extracting-top-20-30-observations-group-wise-from-SAS-dataset/m-p/278357#M14686</link>
      <description>&lt;P&gt;There is some sample code in SAS &lt;A href="http://support.sas.com/kb/24/778.html" target="_blank"&gt;note 24778&lt;/A&gt; that explains how to do it in datastep. Depending on how you'd like to deal with ties (equal scores) PROC RANK may also be helpful:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.cars out=cars;
        by make;
run;
proc rank data=sashelp.cars ou=carsrank;
        by make;
        var horsepower;
        ranks hp_r;
run;
proc sort data=carsrank;
        by make hp_r;
        where hp_r &amp;lt;= 5;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Actually, Google on "sas top n by group" gives a myriad of alternatives, each with its own virtues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jun 2016 10:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Extracting-top-20-30-observations-group-wise-from-SAS-dataset/m-p/278357#M14686</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-06-18T10:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting top 20 - 30 observations group wise from SAS dataset</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Extracting-top-20-30-observations-group-wise-from-SAS-dataset/m-p/278369#M14687</link>
      <description>&lt;P&gt;1. Sort dataset by group and variable of interest&lt;/P&gt;
&lt;P&gt;2. Add a counter to count the values&lt;/P&gt;
&lt;P&gt;3. Take top N as desired&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Assuming N = 5, take top 5 tallest students by sex; 

*1 - sort by variables;
proc sort data=sashelp.class out=class;
by sex descending height;
run;


data want;
set class;
by sex;

*Create counter for each group;
if first.sex then count=1;
else count+1;

*Extract based on N;
if count&amp;lt;5;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 18 Jun 2016 13:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Extracting-top-20-30-observations-group-wise-from-SAS-dataset/m-p/278369#M14687</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-18T13:12:19Z</dc:date>
    </item>
  </channel>
</rss>

