<?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: How to get ONLY the five maximum obs. within each month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-ONLY-the-five-maximum-obs-within-each-month/m-p/411886#M279757</link>
    <description>&lt;P&gt;Thanks! Any additional code to&amp;nbsp;retrieve the first 5 observations?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=max2 obs=5;&amp;nbsp; /* it does not work */&lt;BR /&gt;by permno year month; &lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Nov 2017 12:10:14 GMT</pubDate>
    <dc:creator>ZZB</dc:creator>
    <dc:date>2017-11-09T12:10:14Z</dc:date>
    <item>
      <title>How to get ONLY the five maximum obs. within each month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-ONLY-the-five-maximum-obs-within-each-month/m-p/411878#M279755</link>
      <description>&lt;P&gt;For each ID, it has year, month, and day observations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to get the five largest numbers within each month for each ID. How to get it?&lt;BR /&gt;I can use "proc sort; by ID year month obs" to rank the obs within each month, but I do not know how to get only the five largest numbers.&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 11:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-ONLY-the-five-maximum-obs-within-each-month/m-p/411878#M279755</guid>
      <dc:creator>ZZB</dc:creator>
      <dc:date>2017-11-09T11:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to get ONLY the five maximum obs. within each month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-ONLY-the-five-maximum-obs-within-each-month/m-p/411882#M279756</link>
      <description>&lt;P&gt;Sort&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by id year month descending obs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then retrieve the first 5 observations&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by id year month;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Nov 2017 11:55:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-ONLY-the-five-maximum-obs-within-each-month/m-p/411882#M279756</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-09T11:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to get ONLY the five maximum obs. within each month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-ONLY-the-five-maximum-obs-within-each-month/m-p/411886#M279757</link>
      <description>&lt;P&gt;Thanks! Any additional code to&amp;nbsp;retrieve the first 5 observations?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=max2 obs=5;&amp;nbsp; /* it does not work */&lt;BR /&gt;by permno year month; &lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 12:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-ONLY-the-five-maximum-obs-within-each-month/m-p/411886#M279757</guid>
      <dc:creator>ZZB</dc:creator>
      <dc:date>2017-11-09T12:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to get ONLY the five maximum obs. within each month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-ONLY-the-five-maximum-obs-within-each-month/m-p/411889#M279758</link>
      <description>&lt;P&gt;You have to do a count within each by group:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=max2;
by permno year month descending obs;
run;

data want;
set max2;
by permno year month;
retain counter;
if first.month
then counter = 1;
else counter + 1;
if counter le 5;
drop counter;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;assuming that "obs" is a variable already present in the dataset. If you need to create that for each day, it can be done similar to the above code, or by using proc freq.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 12:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-ONLY-the-five-maximum-obs-within-each-month/m-p/411889#M279758</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-09T12:15:15Z</dc:date>
    </item>
  </channel>
</rss>

