<?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 Create Subgroup ID in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Create-Subgroup-ID/m-p/973356#M43453</link>
    <description>&lt;P&gt;I would like to create a new identifier (new_id) that identifies a new subgroup whenever the indicator switches from 0 to 1. Has some and idea how to accomplish this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="3" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="64" height="19" style="height: 14.4pt; width: 48pt;"&gt;group_id&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;indicator&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;new_id&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;1a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;1a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;1a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;1b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;1b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;1b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;1b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;2a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;2a&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
    <pubDate>Tue, 26 Aug 2025 20:36:03 GMT</pubDate>
    <dc:creator>trevand</dc:creator>
    <dc:date>2025-08-26T20:36:03Z</dc:date>
    <item>
      <title>Create Subgroup ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-Subgroup-ID/m-p/973356#M43453</link>
      <description>&lt;P&gt;I would like to create a new identifier (new_id) that identifies a new subgroup whenever the indicator switches from 0 to 1. Has some and idea how to accomplish this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="3" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="64" height="19" style="height: 14.4pt; width: 48pt;"&gt;group_id&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;indicator&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;new_id&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;1a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;1a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;1a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;1b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;1b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;1b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;1b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;2a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" style="height: 14.4pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;2a&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 26 Aug 2025 20:36:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-Subgroup-ID/m-p/973356#M43453</guid>
      <dc:creator>trevand</dc:creator>
      <dc:date>2025-08-26T20:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create Subgroup ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-Subgroup-ID/m-p/973357#M43454</link>
      <description>&lt;P&gt;Much much much easier to create sequential numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    if indicator=1 then new_id+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm pretty sure anything you want to do with this NEW_ID variable can be done with the sequential numbers.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Aug 2025 20:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-Subgroup-ID/m-p/973357#M43454</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-08-26T20:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create Subgroup ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-Subgroup-ID/m-p/973380#M43455</link>
      <description>&lt;P&gt;Agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;sequences are easier to maintain/use.&lt;/P&gt;
&lt;P&gt;If you need the group_id&amp;nbsp; within the new variable you can try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length group_id indicator 8;
	input group_id indicator;
	datalines;
1 1
1 0
1 0
1 1
1 0
1 0
1 0
2 1
2 0
;
run;

data want;
	set have;
	by group_id;
	if first.group_id then index = 0;
	if indicator = 1 then index+1;
	new_id = cats(put(group_id,best.),'-',put(index,best.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But to get the result you need, try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	by group_id;
	if first.group_id then index = 0;
	if indicator = 1 then index+1;
	new_id = cats(put(group_id,best.),substr('abcdefghijklmnopqrstuvwxyz',index,1));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It was not clear from your example how many times the indicator can change, but I guess the maximum with this technique&amp;nbsp; would be 26.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 06:56:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-Subgroup-ID/m-p/973380#M43455</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2025-08-27T06:56:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create Subgroup ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-Subgroup-ID/m-p/973384#M43457</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466351"&gt;@trevand&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please tell us what you are going to do with variable NEW_ID&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 09:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-Subgroup-ID/m-p/973384#M43457</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-08-27T09:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create Subgroup ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-Subgroup-ID/m-p/973392#M43458</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;sequences are easier to maintain/use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It was not clear from your example how many times the indicator can change, but I guess the maximum with this technique&amp;nbsp; would be 26.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Good point. That's a problem if you need more than 26 letters. Another problem is that if the variable GROUP_ID goes above 9, then the next value of NEW_ID is 10a. Since you also have 1a, these will not sort properly. If you sort on these NEW_ID values, 10a, 10b, ... will be followed by 1a. And if GROUP_ID goes above 9, you will also need a LENGTH statement to make this work at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus I am skeptical that there is a valid use for identifiers like 1a and 10a and so on. Who can remember what they represent when looking at the output? I also worry that the OP has oversimplified a real world problem and any answers we give will not fit the real world problem.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 12:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-Subgroup-ID/m-p/973392#M43458</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-08-27T12:24:25Z</dc:date>
    </item>
  </channel>
</rss>

