<?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 Assign a meta ID to consecutive rows that share the same ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assign-a-meta-ID-to-consecutive-rows-that-share-the-same-ID/m-p/345131#M79366</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a datset with individual ID and group ID. A person can move from one group to the other, sometimes back to the same group. I'd like to assign another group ID to identify those with the same Group in consecutive order. Say for ID=3, the person moved from group 25 then 27, 27 and 25...., I'd like to assign GroupID2 to the first four rows as 1 (for group 25), 2 for the next two rows where group id is both 27), and 3 for the 4th row when the person return to the same Group I 25, etc..&amp;nbsp;How do I do it? Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&amp;nbsp;have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input id groupID Amount;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;1 11 13&lt;/P&gt;
&lt;P&gt;1 12 45&lt;/P&gt;
&lt;P&gt;2 21 30&lt;/P&gt;
&lt;P&gt;2 21 20&lt;/P&gt;
&lt;P&gt;2 22 15&lt;/P&gt;
&lt;P&gt;3 25 34&lt;/P&gt;
&lt;P&gt;3 27 25&lt;/P&gt;
&lt;P&gt;3 27 15&lt;/P&gt;
&lt;P&gt;3 25 14&lt;/P&gt;
&lt;P&gt;3 25 30&lt;/P&gt;
&lt;P&gt;3 25 24&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data for Group 2 (3rd column) should&amp;nbsp;look like this:&lt;/P&gt;
&lt;P&gt;ID, GroupID, GroupID2, Amount:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;1&lt;/STRONG&gt; &lt;STRONG&gt;11&lt;/STRONG&gt; &lt;STRONG&gt;1&lt;/STRONG&gt; &lt;STRONG&gt;13&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt; &lt;STRONG&gt;12&lt;/STRONG&gt; &lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;45&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;21&lt;/STRONG&gt; &lt;STRONG&gt;1&lt;/STRONG&gt; &lt;STRONG&gt;30&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;21&lt;/STRONG&gt; &lt;STRONG&gt;1&lt;/STRONG&gt; &lt;STRONG&gt;20&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;22&lt;/STRONG&gt; &lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;15&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt; &lt;STRONG&gt;25&lt;/STRONG&gt; &lt;STRONG&gt;1&lt;/STRONG&gt; &lt;STRONG&gt;34&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt; &lt;STRONG&gt;27&lt;/STRONG&gt; &lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;25&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt; &lt;STRONG&gt;27&lt;/STRONG&gt; &lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;15&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt; &lt;STRONG&gt;25&lt;/STRONG&gt; &lt;STRONG&gt;3&lt;/STRONG&gt; &lt;STRONG&gt;14&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;3 25 3 30&lt;/P&gt;
&lt;P&gt;3 25 3 24&lt;/P&gt;</description>
    <pubDate>Tue, 28 Mar 2017 19:26:04 GMT</pubDate>
    <dc:creator>Solph</dc:creator>
    <dc:date>2017-03-28T19:26:04Z</dc:date>
    <item>
      <title>Assign a meta ID to consecutive rows that share the same ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-a-meta-ID-to-consecutive-rows-that-share-the-same-ID/m-p/345131#M79366</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a datset with individual ID and group ID. A person can move from one group to the other, sometimes back to the same group. I'd like to assign another group ID to identify those with the same Group in consecutive order. Say for ID=3, the person moved from group 25 then 27, 27 and 25...., I'd like to assign GroupID2 to the first four rows as 1 (for group 25), 2 for the next two rows where group id is both 27), and 3 for the 4th row when the person return to the same Group I 25, etc..&amp;nbsp;How do I do it? Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&amp;nbsp;have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input id groupID Amount;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;1 11 13&lt;/P&gt;
&lt;P&gt;1 12 45&lt;/P&gt;
&lt;P&gt;2 21 30&lt;/P&gt;
&lt;P&gt;2 21 20&lt;/P&gt;
&lt;P&gt;2 22 15&lt;/P&gt;
&lt;P&gt;3 25 34&lt;/P&gt;
&lt;P&gt;3 27 25&lt;/P&gt;
&lt;P&gt;3 27 15&lt;/P&gt;
&lt;P&gt;3 25 14&lt;/P&gt;
&lt;P&gt;3 25 30&lt;/P&gt;
&lt;P&gt;3 25 24&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data for Group 2 (3rd column) should&amp;nbsp;look like this:&lt;/P&gt;
&lt;P&gt;ID, GroupID, GroupID2, Amount:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;1&lt;/STRONG&gt; &lt;STRONG&gt;11&lt;/STRONG&gt; &lt;STRONG&gt;1&lt;/STRONG&gt; &lt;STRONG&gt;13&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt; &lt;STRONG&gt;12&lt;/STRONG&gt; &lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;45&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;21&lt;/STRONG&gt; &lt;STRONG&gt;1&lt;/STRONG&gt; &lt;STRONG&gt;30&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;21&lt;/STRONG&gt; &lt;STRONG&gt;1&lt;/STRONG&gt; &lt;STRONG&gt;20&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;22&lt;/STRONG&gt; &lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;15&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt; &lt;STRONG&gt;25&lt;/STRONG&gt; &lt;STRONG&gt;1&lt;/STRONG&gt; &lt;STRONG&gt;34&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt; &lt;STRONG&gt;27&lt;/STRONG&gt; &lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;25&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt; &lt;STRONG&gt;27&lt;/STRONG&gt; &lt;STRONG&gt;2&lt;/STRONG&gt; &lt;STRONG&gt;15&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt; &lt;STRONG&gt;25&lt;/STRONG&gt; &lt;STRONG&gt;3&lt;/STRONG&gt; &lt;STRONG&gt;14&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;3 25 3 30&lt;/P&gt;
&lt;P&gt;3 25 3 24&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 19:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-a-meta-ID-to-consecutive-rows-that-share-the-same-ID/m-p/345131#M79366</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2017-03-28T19:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: Assign a meta ID to consecutive rows that share the same ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-a-meta-ID-to-consecutive-rows-that-share-the-same-ID/m-p/345142#M79370</link>
      <description>&lt;PRE&gt;data want;
  set have;
  by id groupID notsorted;
  if first.id then groupID2=0;
  if first.groupID then groupID2+1;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 19:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-a-meta-ID-to-consecutive-rows-that-share-the-same-ID/m-p/345142#M79370</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-28T19:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Assign a meta ID to consecutive rows that share the same ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-a-meta-ID-to-consecutive-rows-that-share-the-same-ID/m-p/345153#M79374</link>
      <description>&lt;P&gt;Thanks a lot. Such a clever way, and so simple and straightforward.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2017 20:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-a-meta-ID-to-consecutive-rows-that-share-the-same-ID/m-p/345153#M79374</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2017-03-28T20:08:07Z</dc:date>
    </item>
  </channel>
</rss>

