<?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 create a group id in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-group-id/m-p/911280#M359349</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a have dataset, I want to create a group seq based on:&lt;/P&gt;
&lt;P&gt;if id is the same;&lt;/P&gt;
&lt;P&gt;if yn=1 and seq are connected to each other, then they belong to same group;&lt;/P&gt;
&lt;P&gt;How can I create new_seq?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="stataq_0-1704985902761.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92454i742B64DD9768FCB3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="stataq_0-1704985902761.png" alt="stataq_0-1704985902761.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sample data:&lt;/P&gt;
&lt;P&gt;data have ;&lt;BR /&gt;input id seq yn ;&lt;BR /&gt;cards;&lt;BR /&gt;1 1 .&lt;BR /&gt;1 2 .&lt;BR /&gt;1 3 1&lt;BR /&gt;1 4 1&lt;BR /&gt;1 5 .&lt;BR /&gt;1 6 .&lt;BR /&gt;1 7 .&lt;BR /&gt;1 8 1&lt;BR /&gt;1 9 1&lt;BR /&gt;1 10 1&lt;BR /&gt;1 11 .&lt;BR /&gt;1 12 .&lt;BR /&gt;1 13 1&lt;BR /&gt;1 14 1&lt;BR /&gt;1 15 .&lt;BR /&gt;1 16 1&lt;BR /&gt;1 17 1&lt;BR /&gt;2 1 1&lt;BR /&gt;2 2 .&lt;BR /&gt;2 3 1&lt;BR /&gt;2 4 1&lt;BR /&gt;2 5 .&lt;BR /&gt;2 6 .&lt;BR /&gt;2 7 1&lt;BR /&gt;2 8 1&lt;BR /&gt;2 9 .&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jan 2024 15:14:38 GMT</pubDate>
    <dc:creator>stataq</dc:creator>
    <dc:date>2024-01-11T15:14:38Z</dc:date>
    <item>
      <title>how to create a group id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-group-id/m-p/911280#M359349</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a have dataset, I want to create a group seq based on:&lt;/P&gt;
&lt;P&gt;if id is the same;&lt;/P&gt;
&lt;P&gt;if yn=1 and seq are connected to each other, then they belong to same group;&lt;/P&gt;
&lt;P&gt;How can I create new_seq?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="stataq_0-1704985902761.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92454i742B64DD9768FCB3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="stataq_0-1704985902761.png" alt="stataq_0-1704985902761.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sample data:&lt;/P&gt;
&lt;P&gt;data have ;&lt;BR /&gt;input id seq yn ;&lt;BR /&gt;cards;&lt;BR /&gt;1 1 .&lt;BR /&gt;1 2 .&lt;BR /&gt;1 3 1&lt;BR /&gt;1 4 1&lt;BR /&gt;1 5 .&lt;BR /&gt;1 6 .&lt;BR /&gt;1 7 .&lt;BR /&gt;1 8 1&lt;BR /&gt;1 9 1&lt;BR /&gt;1 10 1&lt;BR /&gt;1 11 .&lt;BR /&gt;1 12 .&lt;BR /&gt;1 13 1&lt;BR /&gt;1 14 1&lt;BR /&gt;1 15 .&lt;BR /&gt;1 16 1&lt;BR /&gt;1 17 1&lt;BR /&gt;2 1 1&lt;BR /&gt;2 2 .&lt;BR /&gt;2 3 1&lt;BR /&gt;2 4 1&lt;BR /&gt;2 5 .&lt;BR /&gt;2 6 .&lt;BR /&gt;2 7 1&lt;BR /&gt;2 8 1&lt;BR /&gt;2 9 .&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2024 15:14:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-group-id/m-p/911280#M359349</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-01-11T15:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a group id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-group-id/m-p/911286#M359351</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by id seq;
    prev_yn=lag(yn);
    prev_id=lag(id);
    if first.id then new_seq=.;
    if id=prev_id and yn=1 and prev_yn=. then new_seq+1;
    if yn=. then new_seq_plus_missing=.;
    else new_seq_plus_missing=new_seq;
    drop prev:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jan 2024 15:55:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-group-id/m-p/911286#M359351</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-11T15:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a group id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-group-id/m-p/911290#M359354</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Looks like that misses the first record for ID2, which has yn=1 so is a new seq.&amp;nbsp; Maybe replace&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    if first.id then new_seq=.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    if first.id then new_seq=(yn=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2024 16:17:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-group-id/m-p/911290#M359354</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-01-11T16:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a group id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-group-id/m-p/911296#M359356</link>
      <description>&lt;P&gt;If you can trust that your data are sorted by ID and seq, then you can can use by-group processing to detect the start of each group with yn=1, and increment a counter, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input id seq yn ;
cards;
1 1 .
1 2 .
1 3 1
1 4 1
1 5 .
1 6 .
1 7 .
1 8 1
1 9 1
1 10 1
1 11 .
1 12 .
1 13 1
1 14 1
1 15 .
1 16 1
1 17 1
2 1 1
2 2 .
2 3 1
2 4 1
2 5 .
2 6 .
2 7 1
2 8 1
2 9 .
;         

data want ;
  set have ;
  by id yn notsorted ;
  if first.id then _seqnum=0 ;
  if first.yn and yn=1 then _seqnum++1 ;
  if yn=1 then new_seq=_seqnum ;
  * drop _: ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2024 16:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-group-id/m-p/911296#M359356</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-01-11T16:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a group id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-group-id/m-p/911298#M359358</link>
      <description>&lt;P&gt;"Connected" should be defined. If you mean the variable Seq appears in sequential numeric order then say so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2024 16:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-group-id/m-p/911298#M359358</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-01-11T16:41:07Z</dc:date>
    </item>
  </channel>
</rss>

