<?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 How to count by subgroup? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-by-subgroup/m-p/416403#M102235</link>
    <description>&lt;P&gt;Here is my example dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fruit apple &amp;nbsp;&lt;/P&gt;&lt;P&gt;fruit apple &amp;nbsp;&lt;/P&gt;&lt;P&gt;fruit orange&lt;/P&gt;&lt;P&gt;fruit orange&amp;nbsp;&lt;/P&gt;&lt;P&gt;fruit orange&lt;/P&gt;&lt;P&gt;vegetable celery&lt;/P&gt;&lt;P&gt;vegetable broccoli&amp;nbsp;&lt;/P&gt;&lt;P&gt;meat beef&lt;/P&gt;&lt;P&gt;meat chicken&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I create a third column, that identifies the group number in column 1?&lt;/P&gt;&lt;P&gt;The resulting dataset should look like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fruit apple &amp;nbsp;1&lt;/P&gt;&lt;P&gt;fruit apple &amp;nbsp;1&lt;/P&gt;&lt;P&gt;fruit orange 1&lt;/P&gt;&lt;P&gt;fruit orange 1&lt;/P&gt;&lt;P&gt;fruit orange 1&lt;/P&gt;&lt;P&gt;vegetable celery 2&lt;/P&gt;&lt;P&gt;vegetable broccoli 2&lt;/P&gt;&lt;P&gt;meat beef 3&lt;/P&gt;&lt;P&gt;meat chicken 3&lt;/P&gt;</description>
    <pubDate>Mon, 27 Nov 2017 14:19:04 GMT</pubDate>
    <dc:creator>schoi</dc:creator>
    <dc:date>2017-11-27T14:19:04Z</dc:date>
    <item>
      <title>How to count by subgroup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-by-subgroup/m-p/416403#M102235</link>
      <description>&lt;P&gt;Here is my example dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fruit apple &amp;nbsp;&lt;/P&gt;&lt;P&gt;fruit apple &amp;nbsp;&lt;/P&gt;&lt;P&gt;fruit orange&lt;/P&gt;&lt;P&gt;fruit orange&amp;nbsp;&lt;/P&gt;&lt;P&gt;fruit orange&lt;/P&gt;&lt;P&gt;vegetable celery&lt;/P&gt;&lt;P&gt;vegetable broccoli&amp;nbsp;&lt;/P&gt;&lt;P&gt;meat beef&lt;/P&gt;&lt;P&gt;meat chicken&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I create a third column, that identifies the group number in column 1?&lt;/P&gt;&lt;P&gt;The resulting dataset should look like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fruit apple &amp;nbsp;1&lt;/P&gt;&lt;P&gt;fruit apple &amp;nbsp;1&lt;/P&gt;&lt;P&gt;fruit orange 1&lt;/P&gt;&lt;P&gt;fruit orange 1&lt;/P&gt;&lt;P&gt;fruit orange 1&lt;/P&gt;&lt;P&gt;vegetable celery 2&lt;/P&gt;&lt;P&gt;vegetable broccoli 2&lt;/P&gt;&lt;P&gt;meat beef 3&lt;/P&gt;&lt;P&gt;meat chicken 3&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 14:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-by-subgroup/m-p/416403#M102235</guid>
      <dc:creator>schoi</dc:creator>
      <dc:date>2017-11-27T14:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to count by subgroup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-by-subgroup/m-p/416405#M102236</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by col1 notsorted;
retain subgroup 0;
if first.col1 then subgroup + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You might consider sorting by col1 first, so you can omit the notsorted option and make sure that a certain subgroup does not receive more than one number.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 14:25:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-by-subgroup/m-p/416405#M102236</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-27T14:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to count by subgroup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-by-subgroup/m-p/416414#M102238</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have other string columns in my RETAIN statement. &amp;nbsp;It doesn't seem to work if I put those columns in front of subgroup 0. &amp;nbsp;Anyway around this?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 14:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-by-subgroup/m-p/416414#M102238</guid>
      <dc:creator>schoi</dc:creator>
      <dc:date>2017-11-27T14:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to count by subgroup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-by-subgroup/m-p/416415#M102239</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input food$ type$;
datalines;
fruit apple  
fruit apple  
fruit orange
fruit orange 
fruit orange
vegetable celery
vegetable broccoli 
meat beef
meat chicken
;

proc sort data=have;
	by food;
run;

data want;
	set have;
	by food;
	if first.food then groupnum+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Nov 2017 14:49:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-by-subgroup/m-p/416415#M102239</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-11-27T14:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to count by subgroup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-by-subgroup/m-p/416432#M102241</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/178762"&gt;@schoi&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have other string columns in my RETAIN statement. &amp;nbsp;It doesn't seem to work if I put those columns in front of subgroup 0. &amp;nbsp;Anyway around this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In order for in-depth help, post your code (with log if code fails with ERROR or WARNING) and some example data to test the code against. See &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;'s example data step for how to post data.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 15:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-by-subgroup/m-p/416432#M102241</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-27T15:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to count by subgroup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-by-subgroup/m-p/416445#M102247</link>
      <description>&lt;P&gt;Thanks everyone!&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 15:57:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-by-subgroup/m-p/416445#M102247</guid>
      <dc:creator>schoi</dc:creator>
      <dc:date>2017-11-27T15:57:15Z</dc:date>
    </item>
  </channel>
</rss>

