<?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: Count by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-by-group/m-p/277550#M55751</link>
    <description>&lt;P&gt;It is possible to achieve the same results using data step, Hash or DOW can be utilized. The following code is an example using 2XDOW:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input ID ID2;
	cards;
1 11 
1 11 
1 11 
1 22 
1 22 
1 22 
2 12 
2 12 
2 16 
;

data want;
	do until (last.id);
		set have;
		by id id2;

		if first.id then
			call missing (_id,_id2);

		if first.id2 then
			do;
				_id=max(_id,_id2);
				_id2=1;
			end;
		else _id2+1;
	end;

	do until (last.id);
		set have;
		by id id2;

		if first.id2 then
			do;
				_id2=1;
			end;
		else _id2+1;

		if last.id2 and _id2=_id then
			output;
	end;

	drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 15 Jun 2016 13:16:04 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2016-06-15T13:16:04Z</dc:date>
    <item>
      <title>Count by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-by-group/m-p/277372#M55677</link>
      <description>&lt;P&gt;I want to calculate maximum number of times a value appear by group. For example, in the table below, 11 appears thrice in a group value of 1 and 22 appears twice in a group value of 1. So i want 1 11 in a row as 11 appears maximum times. Same logic holds for a ID value of 2. In that case, 12 22 should come out in a row. In the final output table, i need 2 rows as explained above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="2" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;ID2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;22&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;22&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;16&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 14 Jun 2016 20:24:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-by-group/m-p/277372#M55677</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2016-06-14T20:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: Count by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-by-group/m-p/277373#M55678</link>
      <description>&lt;P&gt;What do you want to do if two or more values of ID2 appear the same number of times such as:&lt;/P&gt;
&lt;TABLE width="128" style="width: 96pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD width="64" height="20" style="width: 48pt; height: 15pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;ID2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;22&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;22&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;22&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="height: 15pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;16&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Would you want 1 11 or 1 22? And the logic between picking the two?&lt;/P&gt;
&lt;P&gt;(NOTE: I modified your data so 1 11 and 1 22 both appear 3 times)&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2016 20:29:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-by-group/m-p/277373#M55678</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-06-14T20:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-by-group/m-p/277374#M55679</link>
      <description>&lt;P&gt;Here is quick &amp;amp; dirty SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select distinct id,id2 from
(select id,id2,count(*) as ct from have group by id,id2) 
group by id
having ct=max(ct)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jun 2016 20:34:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-by-group/m-p/277374#M55679</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-06-14T20:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Count by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-by-group/m-p/277388#M55686</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;: I want both the cases if they appear equal number of times. Thanks! &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo&lt;/a&gt;: Thanks a ton. Do you suggest the data step method for the same?</description>
      <pubDate>Tue, 14 Jun 2016 21:05:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-by-group/m-p/277388#M55686</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2016-06-14T21:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: Count by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-by-group/m-p/277550#M55751</link>
      <description>&lt;P&gt;It is possible to achieve the same results using data step, Hash or DOW can be utilized. The following code is an example using 2XDOW:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input ID ID2;
	cards;
1 11 
1 11 
1 11 
1 22 
1 22 
1 22 
2 12 
2 12 
2 16 
;

data want;
	do until (last.id);
		set have;
		by id id2;

		if first.id then
			call missing (_id,_id2);

		if first.id2 then
			do;
				_id=max(_id,_id2);
				_id2=1;
			end;
		else _id2+1;
	end;

	do until (last.id);
		set have;
		by id id2;

		if first.id2 then
			do;
				_id2=1;
			end;
		else _id2+1;

		if last.id2 and _id2=_id then
			output;
	end;

	drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Jun 2016 13:16:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-by-group/m-p/277550#M55751</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-06-15T13:16:04Z</dc:date>
    </item>
  </channel>
</rss>

