<?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: grouping the records in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/grouping-the-records/m-p/205451#M51164</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sam,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; for example create one table such as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table one as&lt;/P&gt;&lt;P&gt;select &lt;/P&gt;&lt;P&gt;&amp;nbsp; grp,&lt;/P&gt;&lt;P&gt;&amp;nbsp; id,&lt;/P&gt;&lt;P&gt;&amp;nbsp; count(*) as N&lt;/P&gt;&lt;P&gt;&amp;nbsp; from have group by 1,2&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and then the result&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table result as&lt;/P&gt;&lt;P&gt;select grp,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum(case when N=1 then 1 else 0 end) as chk1,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum(case when N=2 or N=3 then 1 else 0 end) as chk2,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum(case when N&amp;gt;3 then 1 else 0 end) as chk3&lt;/P&gt;&lt;P&gt;from one&lt;/P&gt;&lt;P&gt;group by 1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;/***************************************************************************/&lt;/P&gt;&lt;P&gt;or all in one step&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table result as&lt;/P&gt;&lt;P&gt;select grp,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum(case when N=1 then 1 else 0 end) as chk1,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum(case when N=2 or N=3 then 1 else 0 end) as chk2,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum(case when N&amp;gt;3 then 1 else 0 end) as chk3&lt;/P&gt;&lt;P&gt;from&lt;/P&gt;&lt;P&gt;&amp;nbsp; (select &lt;/P&gt;&lt;P&gt;&amp;nbsp; grp,&lt;/P&gt;&lt;P&gt;&amp;nbsp; id,&lt;/P&gt;&lt;P&gt;&amp;nbsp; count(*) as N&lt;/P&gt;&lt;P&gt;&amp;nbsp; from have group by 1,2)&lt;/P&gt;&lt;P&gt;group by 1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Jakub&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 19 Mar 2015 08:04:17 GMT</pubDate>
    <dc:creator>chrej5am</dc:creator>
    <dc:date>2015-03-19T08:04:17Z</dc:date>
    <item>
      <title>grouping the records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/grouping-the-records/m-p/205449#M51162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a dataset with id and grp. I need to create 3 variables chk1,chk2 &amp;amp; chk3.&lt;/P&gt;&lt;P&gt;Criteria for chk1 : same grp with with unique subjects(from below example : 101,102,103) will fall under this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; chk2:&amp;nbsp; same grp with more than 2 or 3 times for same subject(from below example : 100 have got multiple time of same grp)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; chk3: same grp with more then 4 time (From below example: no subject satisfy this one so chk3 is 0)&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt; input id $&amp;nbsp; grp $;&lt;/P&gt;&lt;P&gt; cards;&lt;/P&gt;&lt;P&gt; 100&amp;nbsp;&amp;nbsp; test1&lt;/P&gt;&lt;P&gt; 100&amp;nbsp;&amp;nbsp; test1&lt;/P&gt;&lt;P&gt; 101&amp;nbsp;&amp;nbsp; test1&lt;/P&gt;&lt;P&gt; 102&amp;nbsp;&amp;nbsp; test1&lt;/P&gt;&lt;P&gt; 103&amp;nbsp;&amp;nbsp; test1&lt;/P&gt;&lt;P&gt; ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;want :&lt;/P&gt;&lt;P&gt; grp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; chk1&amp;nbsp;&amp;nbsp;&amp;nbsp; chk2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; chk3&lt;/P&gt;&lt;P&gt; test1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Sam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Mar 2015 04:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/grouping-the-records/m-p/205449#M51162</guid>
      <dc:creator>sam369</dc:creator>
      <dc:date>2015-03-19T04:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: grouping the records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/grouping-the-records/m-p/205450#M51163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;Hi Sam,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;Just to check I understand it correctly:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;chk1: number of distinct IDs in the group&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;chk2: this is a binary variable. chk2=1 if there exists an ID in the group, with more then 2 occurrences.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;chk3: &lt;SPAN style="font-size: 13.3333330154419px;"&gt;this is a binary variable. chk3=1 if there exists an ID in the group, with more then 4 occurrences.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;OK, now I understand.&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333330154419px; text-decoration: line-through;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Gergely Bathó&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Mar 2015 07:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/grouping-the-records/m-p/205450#M51163</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2015-03-19T07:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: grouping the records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/grouping-the-records/m-p/205451#M51164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sam,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; for example create one table such as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table one as&lt;/P&gt;&lt;P&gt;select &lt;/P&gt;&lt;P&gt;&amp;nbsp; grp,&lt;/P&gt;&lt;P&gt;&amp;nbsp; id,&lt;/P&gt;&lt;P&gt;&amp;nbsp; count(*) as N&lt;/P&gt;&lt;P&gt;&amp;nbsp; from have group by 1,2&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and then the result&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table result as&lt;/P&gt;&lt;P&gt;select grp,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum(case when N=1 then 1 else 0 end) as chk1,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum(case when N=2 or N=3 then 1 else 0 end) as chk2,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum(case when N&amp;gt;3 then 1 else 0 end) as chk3&lt;/P&gt;&lt;P&gt;from one&lt;/P&gt;&lt;P&gt;group by 1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;/***************************************************************************/&lt;/P&gt;&lt;P&gt;or all in one step&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table result as&lt;/P&gt;&lt;P&gt;select grp,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum(case when N=1 then 1 else 0 end) as chk1,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum(case when N=2 or N=3 then 1 else 0 end) as chk2,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum(case when N&amp;gt;3 then 1 else 0 end) as chk3&lt;/P&gt;&lt;P&gt;from&lt;/P&gt;&lt;P&gt;&amp;nbsp; (select &lt;/P&gt;&lt;P&gt;&amp;nbsp; grp,&lt;/P&gt;&lt;P&gt;&amp;nbsp; id,&lt;/P&gt;&lt;P&gt;&amp;nbsp; count(*) as N&lt;/P&gt;&lt;P&gt;&amp;nbsp; from have group by 1,2)&lt;/P&gt;&lt;P&gt;group by 1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Jakub&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Mar 2015 08:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/grouping-the-records/m-p/205451#M51164</guid>
      <dc:creator>chrej5am</dc:creator>
      <dc:date>2015-03-19T08:04:17Z</dc:date>
    </item>
  </channel>
</rss>

