<?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: getting a group of observations with maximum count in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336566#M76308</link>
    <description>&lt;P&gt;Here is another possibility, that provides&amp;nbsp;a bit more information just in case you need it.&amp;nbsp; For example, it is conceivable that you need to find the dropoff ... for the ID with the highest count, how many more does it have compared to the next highest count.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=claims order=freq;&lt;/P&gt;
&lt;P&gt;tables ID / noprint out=want (keep=id count);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This gives you an output data set with a count of observations for every ID in your data set.&amp;nbsp; The order is from highest to lowest count, so the first observation has the highest count.&amp;nbsp;&amp;nbsp;Note that it is possible there&amp;nbsp;are ties, and 5 different IDs have the same "highest" count.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Feb 2017 14:18:07 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-02-28T14:18:07Z</dc:date>
    <item>
      <title>getting a group of observations with maximum count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336477#M76282</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have the date in the below format&amp;nbsp; and need to get the group of ID which is having maximum count/observations( In the below example CML0005)&amp;nbsp;. It's just an example , i've a millions of records and need to get the ID having maximum number of observations.&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; claims;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ID $ loss_code $;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;cards4&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;CML0001 27&lt;/P&gt;&lt;P&gt;CML0002 27C&lt;/P&gt;&lt;P&gt;CML0002 27&lt;/P&gt;&lt;P&gt;CML0003 27Y&lt;/P&gt;&lt;P&gt;CML0003 27C&lt;/P&gt;&lt;P&gt;CML0003 27P&lt;/P&gt;&lt;P&gt;CML0004 27O&lt;/P&gt;&lt;P&gt;CML0004 27Y&lt;/P&gt;&lt;P&gt;CML0004 27&lt;/P&gt;&lt;P&gt;CML0004 27P&lt;/P&gt;&lt;P&gt;CML0005 27P&lt;/P&gt;&lt;P&gt;CML0005 27O&lt;/P&gt;&lt;P&gt;CML0005 27C&lt;/P&gt;&lt;P&gt;CML0005 27&lt;/P&gt;&lt;P&gt;CML0006 27Y&lt;/P&gt;&lt;P&gt;CML0006 27C&lt;/P&gt;&lt;P&gt;CML0007 27O&lt;/P&gt;&lt;P&gt;CML0007 27Y&lt;/P&gt;&lt;P&gt;CML0008 27O&lt;/P&gt;&lt;P&gt;CML0009 27P&lt;/P&gt;&lt;P&gt;;;;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thnaks in advance...!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 09:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336477#M76282</guid>
      <dc:creator>Reddi</dc:creator>
      <dc:date>2017-02-28T09:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: getting a group of observations with maximum count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336478#M76283</link>
      <description>&lt;P&gt;Post test data in the form of a datastep, as such this code is a just a guess:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  distinct ID
  from    HAVE&lt;BR /&gt;  group by ID
  having count(*)=max(count(*));
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Feb 2017 09:29:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336478#M76283</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-28T09:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: getting a group of observations with maximum count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336480#M76284</link>
      <description>&lt;P&gt;Like this? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Codes $;
infile datalines;
datalines;
CML0001	27
CML0002	27C
CML0002	27
CML0003	27Y
CML0003	27C
CML0003	27P
CML0004	27O
CML0004	27Y
CML0004	27
CML0004	27P
CML0005	27P
CML0005	27O
CML0005	27C
CML0005	27
CML0006	27Y
CML0006	27C
CML0007	27O
CML0007	27Y
CML0008	27O
CML0009	27P
CML0006	27Y
CML0006	27C
CML0007	27O
CML0007	27Y
CML0008	27O
CML0009	27P
CML0005	27O
;

proc sql;
   create table want as
   select ID, count(ID) as countid
   from have
   group by ID;
quit;

proc sort data = want;
   by descending countid;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Feb 2017 09:31:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336480#M76284</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-02-28T09:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: getting a group of observations with maximum count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336481#M76285</link>
      <description>&lt;P&gt;Sorry ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can use the below code to create a data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; claims;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ID $ loss_code $;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;cards4&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;CML0001 27&lt;/P&gt;&lt;P&gt;CML0002 27C&lt;/P&gt;&lt;P&gt;CML0002 27&lt;/P&gt;&lt;P&gt;CML0003 27Y&lt;/P&gt;&lt;P&gt;CML0003 27C&lt;/P&gt;&lt;P&gt;CML0003 27P&lt;/P&gt;&lt;P&gt;CML0004 27O&lt;/P&gt;&lt;P&gt;CML0004 27Y&lt;/P&gt;&lt;P&gt;CML0004 27&lt;/P&gt;&lt;P&gt;CML0004 27P&lt;/P&gt;&lt;P&gt;CML0005 27P&lt;/P&gt;&lt;P&gt;CML0005 27O&lt;/P&gt;&lt;P&gt;CML0005 27C&lt;/P&gt;&lt;P&gt;CML0005 27&lt;/P&gt;&lt;P&gt;CML0006 27Y&lt;/P&gt;&lt;P&gt;CML0006 27C&lt;/P&gt;&lt;P&gt;CML0007 27O&lt;/P&gt;&lt;P&gt;CML0007 27Y&lt;/P&gt;&lt;P&gt;CML0008 27O&lt;/P&gt;&lt;P&gt;CML0009 27P&lt;/P&gt;&lt;P&gt;;;;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 09:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336481#M76285</guid>
      <dc:creator>Reddi</dc:creator>
      <dc:date>2017-02-28T09:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: getting a group of observations with maximum count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336566#M76308</link>
      <description>&lt;P&gt;Here is another possibility, that provides&amp;nbsp;a bit more information just in case you need it.&amp;nbsp; For example, it is conceivable that you need to find the dropoff ... for the ID with the highest count, how many more does it have compared to the next highest count.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=claims order=freq;&lt;/P&gt;
&lt;P&gt;tables ID / noprint out=want (keep=id count);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This gives you an output data set with a count of observations for every ID in your data set.&amp;nbsp; The order is from highest to lowest count, so the first observation has the highest count.&amp;nbsp;&amp;nbsp;Note that it is possible there&amp;nbsp;are ties, and 5 different IDs have the same "highest" count.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 14:18:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336566#M76308</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-28T14:18:07Z</dc:date>
    </item>
    <item>
      <title>Re: getting a group of observations with maximum count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336865#M76414</link>
      <description>&lt;P&gt;Hi Astounding ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks but i'm looking for the highest count ID/ID's only not all the ID's with individual count.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 08:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336865#M76414</guid>
      <dc:creator>Reddi</dc:creator>
      <dc:date>2017-03-01T08:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: getting a group of observations with maximum count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336871#M76416</link>
      <description>&lt;P&gt;What do you want to do with the&amp;nbsp;&lt;SPAN&gt;highest count ID/ID's, do you just want them in a dataset or to read it into a macrovariable?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 09:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336871#M76416</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-03-01T09:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: getting a group of observations with maximum count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336979#M76453</link>
      <description>Hi ,&lt;BR /&gt;Either way is good for me</description>
      <pubDate>Wed, 01 Mar 2017 14:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/336979#M76453</guid>
      <dc:creator>Reddi</dc:creator>
      <dc:date>2017-03-01T14:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: getting a group of observations with maximum count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/337001#M76462</link>
      <description>&lt;P&gt;The code RW9 posted above will get you what you're looking for: only those ID/IDs with the highest count. If you also&amp;nbsp;want the count included in the result along with the ID, add 'count(*)' to the select statement, the rest of the query remains the same.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 14:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/getting-a-group-of-observations-with-maximum-count/m-p/337001#M76462</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-03-01T14:37:44Z</dc:date>
    </item>
  </channel>
</rss>

