<?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 Getting top two values (counts of categories) by id in proc sql in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Getting-top-two-values-counts-of-categories-by-id-in-proc-sql/m-p/299389#M60442</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to achieve is the following :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to count the categories by the ID i have and to keep only the top &amp;nbsp;two &amp;nbsp;frequent&amp;nbsp;for every ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried&lt;/P&gt;&lt;P&gt;count distinct categories grouping by ID with a proc sql statement &amp;nbsp;by I get stuck on the next step where i want to keep the top 2 by every ID, for example if i just wanted the top value per ID i would take the max but how does that work for getting the second max value as well?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards and thank you in advance&lt;/P&gt;</description>
    <pubDate>Mon, 19 Sep 2016 19:56:49 GMT</pubDate>
    <dc:creator>ConsAth</dc:creator>
    <dc:date>2016-09-19T19:56:49Z</dc:date>
    <item>
      <title>Getting top two values (counts of categories) by id in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-top-two-values-counts-of-categories-by-id-in-proc-sql/m-p/299389#M60442</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to achieve is the following :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to count the categories by the ID i have and to keep only the top &amp;nbsp;two &amp;nbsp;frequent&amp;nbsp;for every ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried&lt;/P&gt;&lt;P&gt;count distinct categories grouping by ID with a proc sql statement &amp;nbsp;by I get stuck on the next step where i want to keep the top 2 by every ID, for example if i just wanted the top value per ID i would take the max but how does that work for getting the second max value as well?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards and thank you in advance&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 19:56:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-top-two-values-counts-of-categories-by-id-in-proc-sql/m-p/299389#M60442</guid>
      <dc:creator>ConsAth</dc:creator>
      <dc:date>2016-09-19T19:56:49Z</dc:date>
    </item>
    <item>
      <title>Re: Getting top two values (counts of categories) by id in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-top-two-values-counts-of-categories-by-id-in-proc-sql/m-p/299395#M60443</link>
      <description>&lt;P&gt;One way, not necessarily the slickest but relatively easy to understand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc freq data=have order=freq noprint;
   table id*categoricalvar/ out=temp;
run;

data want;
   set temp;
   by id;
   retain counter;
   if first.id then counter=1;
   else counter+1;
   if counter le 2 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Sep 2016 20:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-top-two-values-counts-of-categories-by-id-in-proc-sql/m-p/299395#M60443</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-19T20:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Getting top two values (counts of categories) by id in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-top-two-values-counts-of-categories-by-id-in-proc-sql/m-p/299401#M60444</link>
      <description>Very nice and effective than sql and for sure easier to understand thank you very much</description>
      <pubDate>Mon, 19 Sep 2016 20:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-top-two-values-counts-of-categories-by-id-in-proc-sql/m-p/299401#M60444</guid>
      <dc:creator>ConsAth</dc:creator>
      <dc:date>2016-09-19T20:33:53Z</dc:date>
    </item>
  </channel>
</rss>

