<?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: Sas query to get highest 3 rows for date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/767977#M243535</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/390220"&gt;@Sirisha1520&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;am trying using group by clause having count(*) &amp;lt;=3, but its avoiding rows having more than 3 in input file.&amp;nbsp;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Shouldn't that be count(*)&amp;gt;=3 ?&lt;/P&gt;</description>
    <pubDate>Wed, 15 Sep 2021 19:03:14 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-09-15T19:03:14Z</dc:date>
    <item>
      <title>Sas query to get highest 3 rows for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/767967#M243531</link>
      <description>I have a requirement to get highest 3 rows for respective policy and effective date. Key is policy and effective date. am trying using group by clause having count(*) &amp;lt;=3, but its avoiding rows having more than 3 in input file. Please suggest how to write query</description>
      <pubDate>Wed, 15 Sep 2021 18:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/767967#M243531</guid>
      <dc:creator>Sirisha1520</dc:creator>
      <dc:date>2021-09-15T18:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Sas query to get highest 3 rows for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/767977#M243535</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/390220"&gt;@Sirisha1520&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;am trying using group by clause having count(*) &amp;lt;=3, but its avoiding rows having more than 3 in input file.&amp;nbsp;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Shouldn't that be count(*)&amp;gt;=3 ?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 19:03:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/767977#M243535</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-15T19:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: Sas query to get highest 3 rows for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/767978#M243536</link>
      <description>&lt;P&gt;Since "highest 3", assuming you mean largest or greatest, is in effect an order statistic Proc SQL is likely not the best approach in general.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc means documentation has exactly an example of finding the three largest values by grouping variable:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n0afy7c5m16m9dn1s60z9krjmwxq.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n0afy7c5m16m9dn1s60z9krjmwxq.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The key parts are the Idgroup, max (statistic to select with) and out= (number of greatest values to select)&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 19:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/767978#M243536</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-15T19:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sas query to get highest 3 rows for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/767989#M243543</link>
      <description>&lt;P&gt;PROC RANK is probably the best way to do this, as it gives you options on how to handle things in the case where there are ties.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 19:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/767989#M243543</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-15T19:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sas query to get highest 3 rows for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/767998#M243547</link>
      <description>I tried rank but that was giving 1.2, 2.5 , 4.5… so again causing duplicates as i have multple rows for policy with same effective date. Also i have sorted the file for descending order in date due to which taking count less than 3. I need first 3 records for policy with different date. Example below:&lt;BR /&gt;&lt;BR /&gt;0120210101 B&lt;BR /&gt;0120210101 A&lt;BR /&gt;0120210201 C&lt;BR /&gt;0120210301 C&lt;BR /&gt;&lt;BR /&gt;O/p expected:&lt;BR /&gt;&lt;BR /&gt;0120210101 B&lt;BR /&gt;0120210201 C&lt;BR /&gt;0120210301 C&lt;BR /&gt;</description>
      <pubDate>Wed, 15 Sep 2021 20:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/767998#M243547</guid>
      <dc:creator>Sirisha1520</dc:creator>
      <dc:date>2021-09-15T20:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Sas query to get highest 3 rows for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768003#M243550</link>
      <description>&lt;P&gt;&lt;BR /&gt;Don't see any obvious date so "first 3" looks meaningless.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example starting data helps.&lt;/P&gt;
&lt;P&gt;Example output for that input helps more.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 20:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768003#M243550</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-15T20:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Sas query to get highest 3 rows for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768008#M243554</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/390220"&gt;@Sirisha1520&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I tried rank but that was giving 1.2, 2.5 , 4.5… so again causing duplicates as i have multple rows for policy with same effective date. Also i have sorted the file for descending order in date due to which taking count less than 3. I need first 3 records for policy with different date. Example below:&lt;BR /&gt;&lt;BR /&gt;0120210101 B&lt;BR /&gt;0120210101 A&lt;BR /&gt;0120210201 C&lt;BR /&gt;0120210301 C&lt;BR /&gt;&lt;BR /&gt;O/p expected:&lt;BR /&gt;&lt;BR /&gt;0120210101 B&lt;BR /&gt;0120210201 C&lt;BR /&gt;0120210301 C&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, you have ties in your data, and there are many options in PROC RANK on how to handle ties, most likely one of them will be to your liking.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, please don't post unintelligible dates like 0120210101 without an explanation. What is this?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 21:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768008#M243554</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-15T21:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Sas query to get highest 3 rows for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768018#M243559</link>
      <description>Policy Date Plan&lt;BR /&gt;01 20210101 B&lt;BR /&gt;01 20210101 A&lt;BR /&gt;01 20210201 C&lt;BR /&gt;01 20210301 C&lt;BR /&gt;&lt;BR /&gt;O/p expected:&lt;BR /&gt;&lt;BR /&gt;01 20210101 B&lt;BR /&gt;01 20210201 C&lt;BR /&gt;01 20210301 C</description>
      <pubDate>Thu, 16 Sep 2021 03:34:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768018#M243559</guid>
      <dc:creator>Sirisha1520</dc:creator>
      <dc:date>2021-09-16T03:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: Sas query to get highest 3 rows for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768019#M243560</link>
      <description>I was trying to explain this.&lt;BR /&gt;&lt;BR /&gt;Policy Date Plan&lt;BR /&gt;01 20210101 B&lt;BR /&gt;01 20210101 A&lt;BR /&gt;01 20210201 C&lt;BR /&gt;01 20210301 C&lt;BR /&gt;&lt;BR /&gt;O/p expected:&lt;BR /&gt;&lt;BR /&gt;01 20210101 B&lt;BR /&gt;01 20210201 C&lt;BR /&gt;01 20210301 C</description>
      <pubDate>Thu, 16 Sep 2021 03:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768019#M243560</guid>
      <dc:creator>Sirisha1520</dc:creator>
      <dc:date>2021-09-16T03:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Sas query to get highest 3 rows for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768028#M243565</link>
      <description>&lt;P&gt;Let me help you formulate your question:&lt;/P&gt;
&lt;P&gt;First, you want to have only max of Plan for any single date within a Policy.&lt;/P&gt;
&lt;P&gt;Next, you want the earliest three dates for any given Policy.&lt;/P&gt;
&lt;P&gt;Is that correct?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 06:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768028#M243565</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-16T06:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Sas query to get highest 3 rows for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768046#M243569</link>
      <description>Yessss</description>
      <pubDate>Thu, 16 Sep 2021 08:18:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768046#M243569</guid>
      <dc:creator>Sirisha1520</dc:creator>
      <dc:date>2021-09-16T08:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Sas query to get highest 3 rows for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768048#M243570</link>
      <description>&lt;P&gt;Then run this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Policy :$2. Date :yymmdd8. Plan :$1.;
format date yymmdd10.;
datalines;
01 20210101 B
01 20210101 A
01 20210201 C
01 20210301 C
;

proc sort data=have;
by policy date plan;
run;

data want;
set have;
by policy date;
if first.policy then count = 0;
if last.date;
count + 1; /* sum statement implies retain */
if count le 3;
drop count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Sep 2021 08:26:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768048#M243570</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-16T08:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Sas query to get highest 3 rows for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768089#M243585</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/390220"&gt;@Sirisha1520&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Policy Date Plan&lt;BR /&gt;01 20210101 B&lt;BR /&gt;01 20210101 A&lt;BR /&gt;01 20210201 C&lt;BR /&gt;01 20210301 C&lt;BR /&gt;&lt;BR /&gt;O/p expected:&lt;BR /&gt;&lt;BR /&gt;01 20210101 B&lt;BR /&gt;01 20210201 C&lt;BR /&gt;01 20210301 C&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This does not explain the dates. Are they YYYYMMDD or YYYYDDMM?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 11:32:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-query-to-get-highest-3-rows-for-date/m-p/768089#M243585</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-16T11:32:34Z</dc:date>
    </item>
  </channel>
</rss>

