<?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: Selecting 5 max observations per category in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Selecting-5-max-observations-per-category/m-p/32642#M1326</link>
    <description>Thank you so much! This worked perfectly.</description>
    <pubDate>Mon, 18 May 2009 14:43:34 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-05-18T14:43:34Z</dc:date>
    <item>
      <title>Selecting 5 max observations per category</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Selecting-5-max-observations-per-category/m-p/32640#M1324</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I'd like to write some code that selects the 5 biggest firms in a given category. In my mind, it should go something like:&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=source;&lt;BR /&gt;
by category size;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table newtable as select&lt;BR /&gt;
avg(var1) as var1, avg(var2) as var2, sum(var3) as var3&lt;BR /&gt;
from source&lt;BR /&gt;
where (size is in the top 5)&lt;BR /&gt;
group by category;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
However, I'm not sure what the code to determine if it's one of the biggest 5 observations is. Any ideas?&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Fri, 15 May 2009 15:34:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Selecting-5-max-observations-per-category/m-p/32640#M1324</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-15T15:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting 5 max observations per category</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Selecting-5-max-observations-per-category/m-p/32641#M1325</link>
      <description>Hi tbalsky,&lt;BR /&gt;
&lt;BR /&gt;
Please look at the following example. I explained steps in the comments.&lt;BR /&gt;
&lt;BR /&gt;
/* original data set */&lt;BR /&gt;
data firm; input category size @@;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 93458934 1 8467489 1 8679 2 56757 3 57850&lt;BR /&gt;
1 456794 2 697058 2 59876 3 687957 3 698879&lt;BR /&gt;
3 598679 1 8756356 1 356396 1 65365 2 56385&lt;BR /&gt;
2 4686 2 469674967 2 49679674 3 4686 3 47696 &lt;BR /&gt;
3 76946794 3 64868&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
/* sort by category and then by size within each category in descending order */&lt;BR /&gt;
proc sort data=firm; &lt;BR /&gt;
by category DESCENDING size;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* create rank variable within each category */&lt;BR /&gt;
data firm1; set firm;&lt;BR /&gt;
by category;&lt;BR /&gt;
rank+1; &lt;BR /&gt;
if first.category then rank=1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* data set that contains 5 biggest firm within each category */&lt;BR /&gt;
data firm2; set firm1(where=(rank&amp;lt;6));&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 15 May 2009 19:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Selecting-5-max-observations-per-category/m-p/32641#M1325</guid>
      <dc:creator>statsplank</dc:creator>
      <dc:date>2009-05-15T19:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting 5 max observations per category</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Selecting-5-max-observations-per-category/m-p/32642#M1326</link>
      <description>Thank you so much! This worked perfectly.</description>
      <pubDate>Mon, 18 May 2009 14:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Selecting-5-max-observations-per-category/m-p/32642#M1326</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-18T14:43:34Z</dc:date>
    </item>
  </channel>
</rss>

