<?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: Enumerating within by group in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Enumerating-within-by-group/m-p/540598#M16646</link>
    <description>&lt;P&gt;Here's a possibility that assumes your data set is in the right order:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id1 id2;&lt;/P&gt;
&lt;P&gt;if first.id1 then counter=1;&lt;/P&gt;
&lt;P&gt;else if first.id2 then counter + 1;&lt;/P&gt;
&lt;P&gt;if first.id2 then varwant = counter;&lt;/P&gt;
&lt;P&gt;drop counter;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, before dropping COUNTER, take a look at it.&amp;nbsp; Perhaps you prefer that to the VARWANT in your post.&lt;/P&gt;</description>
    <pubDate>Tue, 05 Mar 2019 21:31:02 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-03-05T21:31:02Z</dc:date>
    <item>
      <title>Enumerating within by group</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Enumerating-within-by-group/m-p/540594#M16645</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;My dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID1 ID2&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; a&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; a&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; b&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; a&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; a&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; b&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset I want:&lt;/P&gt;&lt;P&gt;ID1 ID2 varwant&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I do this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thx!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2019 21:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Enumerating-within-by-group/m-p/540594#M16645</guid>
      <dc:creator>KPCklebspn</dc:creator>
      <dc:date>2019-03-05T21:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Enumerating within by group</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Enumerating-within-by-group/m-p/540598#M16646</link>
      <description>&lt;P&gt;Here's a possibility that assumes your data set is in the right order:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id1 id2;&lt;/P&gt;
&lt;P&gt;if first.id1 then counter=1;&lt;/P&gt;
&lt;P&gt;else if first.id2 then counter + 1;&lt;/P&gt;
&lt;P&gt;if first.id2 then varwant = counter;&lt;/P&gt;
&lt;P&gt;drop counter;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, before dropping COUNTER, take a look at it.&amp;nbsp; Perhaps you prefer that to the VARWANT in your post.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2019 21:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Enumerating-within-by-group/m-p/540598#M16646</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-05T21:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Enumerating within by group</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Enumerating-within-by-group/m-p/540629#M16650</link>
      <description>Thanks so much - this works! I am just having a put of difficulty understanding the "if else" part of this.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt;From my understanding, the "if first.id1 then counter=1;" flags the first observation within each id1 group (and if it's not the first observation within the id1 group, then it's a .).&lt;BR /&gt;&lt;BR /&gt;But I'm not clear on what the "else if first.id2 then counter + 1;" does - would you mind explaining? Thank you so much&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 06 Mar 2019 01:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Enumerating-within-by-group/m-p/540629#M16650</guid>
      <dc:creator>KPCklebspn</dc:creator>
      <dc:date>2019-03-06T01:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Enumerating within by group</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Enumerating-within-by-group/m-p/540635#M16651</link>
      <description>&lt;P&gt;By definition, on the first observation for an ID1, both first.id1 and first.id2 are true.&amp;nbsp; Without "else" therefore, the first COUNTER for an ID1 would get incremented twice, ending up with a value of 2 instead of 1.&amp;nbsp; "Else" prevents incrementing COUNTER that second time, until the next time that a new ID2 appears.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 03:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Enumerating-within-by-group/m-p/540635#M16651</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-06T03:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: Enumerating within by group</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Enumerating-within-by-group/m-p/540736#M16658</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID1 ID2 $;
cards;
1     a
1     a
1     b
2     a
2     a
2     b
2     b
;

data want;
set have;
by id1 id2 notsorted;
if first.id1 then n=0;
n+first.id2;
want=n;
if not first.id2 then call missing(want);
drop n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Mar 2019 11:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Enumerating-within-by-group/m-p/540736#M16658</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-03-06T11:33:35Z</dc:date>
    </item>
  </channel>
</rss>

