<?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: Enumeration of variable by repeating group in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Enumeration-of-variable-by-repeating-group/m-p/893060#M82919</link>
    <description>&lt;P&gt;Based on your sample data something like below could work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input vc vn;
  datalines;
1 1
1 1
1 1
1 1
1 1
2 1
2 2
2 1
2 2
2 1
3 1
3 2
3 3
3 1
;

data want(drop=_:);
  set have;
  by vc;
  if first.vc then
    do;
      _s2+1;
      _s1=_s2;
    end;
  else _s1+1;
  vn_calc=1+mod(_s1,_s2);
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1694054564995.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87689i911F53BA1D852E37/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1694054564995.png" alt="Patrick_0-1694054564995.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Sep 2023 02:42:51 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-09-07T02:42:51Z</dc:date>
    <item>
      <title>Enumeration of variable by repeating group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Enumeration-of-variable-by-repeating-group/m-p/893056#M82917</link>
      <description>&lt;P&gt;I have a vehicle count variable that I need to assign a vehicle number from. I think I need an enumeration of some type...the last column is the column I need to create.&amp;nbsp;&lt;/P&gt;&lt;PRE class=""&gt;&lt;CODE class=""&gt;VC VN
&lt;SPAN class=""&gt;1&lt;/SPAN&gt; 1
&lt;SPAN class=""&gt;1&lt;/SPAN&gt; 1
1 1
&lt;SPAN class=""&gt;1 &lt;/SPAN&gt;1
&lt;SPAN class=""&gt;1&lt;/SPAN&gt; 1&lt;/CODE&gt;&lt;BR /&gt;2 1&lt;BR /&gt;2 2&lt;BR /&gt;2 1&lt;BR /&gt;2 2&lt;BR /&gt;2 1&lt;BR /&gt;3 1&lt;BR /&gt;3 2&lt;BR /&gt;3 3&lt;BR /&gt;3 1&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 02:08:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Enumeration-of-variable-by-repeating-group/m-p/893056#M82917</guid>
      <dc:creator>chsprogramming</dc:creator>
      <dc:date>2023-09-07T02:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: Enumeration of variable by repeating group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Enumeration-of-variable-by-repeating-group/m-p/893058#M82918</link>
      <description>&lt;P&gt;Is this a&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Rorschach_test#:~:text=The%20Rorschach%20test%20is%20a,personality%20characteristics%20and%20emotional%20functioning." target="_self"&gt;Rorschach test&lt;/A&gt;&amp;nbsp;?&lt;/P&gt;
&lt;P&gt;I cannot see a pattern there.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you you will need to describe the rule if you us to help you with code to implement it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have never considered&amp;nbsp;Enumeration of a variable.&amp;nbsp; What does that mean?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know how to number OBSERVATIONS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
   obs_number + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I know how to number GROUPS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by group_name;
  group_number + first.group_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I know how to number the members of a group.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by group_name;
  member_number + 1;
  if first.group_name then member_number=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 02:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Enumeration-of-variable-by-repeating-group/m-p/893058#M82918</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-07T02:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: Enumeration of variable by repeating group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Enumeration-of-variable-by-repeating-group/m-p/893060#M82919</link>
      <description>&lt;P&gt;Based on your sample data something like below could work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input vc vn;
  datalines;
1 1
1 1
1 1
1 1
1 1
2 1
2 2
2 1
2 2
2 1
3 1
3 2
3 3
3 1
;

data want(drop=_:);
  set have;
  by vc;
  if first.vc then
    do;
      _s2+1;
      _s1=_s2;
    end;
  else _s1+1;
  vn_calc=1+mod(_s1,_s2);
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1694054564995.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87689i911F53BA1D852E37/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1694054564995.png" alt="Patrick_0-1694054564995.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 02:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Enumeration-of-variable-by-repeating-group/m-p/893060#M82919</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-09-07T02:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Enumeration of variable by repeating group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Enumeration-of-variable-by-repeating-group/m-p/893061#M82920</link>
      <description>&lt;UL&gt;
&lt;LI&gt;Set counter to 1 and first record of each VC&lt;/LI&gt;
&lt;LI&gt;Increment if less than VC, otherwise set back to 1&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by vc;

retain counter;

if first.vc then counter=0;

counter = ifn(counter&amp;lt;VC, counter+1, 1);

/*if counter&amp;lt;VC then counter+1; else counter=1;*/

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/451410"&gt;@chsprogramming&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a vehicle count variable that I need to assign a vehicle number from. I think I need an enumeration of some type...the last column is the column I need to create.&amp;nbsp;&lt;/P&gt;
&lt;PRE class=""&gt;&lt;CODE class=""&gt;VC VN
&lt;SPAN class=""&gt;1&lt;/SPAN&gt; 1
&lt;SPAN class=""&gt;1&lt;/SPAN&gt; 1
1 1
&lt;SPAN class=""&gt;1 &lt;/SPAN&gt;1
&lt;SPAN class=""&gt;1&lt;/SPAN&gt; 1&lt;/CODE&gt;&lt;BR /&gt;2 1&lt;BR /&gt;2 2&lt;BR /&gt;2 1&lt;BR /&gt;2 2&lt;BR /&gt;2 1&lt;BR /&gt;3 1&lt;BR /&gt;3 2&lt;BR /&gt;3 3&lt;BR /&gt;3 1&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 02:49:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Enumeration-of-variable-by-repeating-group/m-p/893061#M82920</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-09-07T02:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Enumeration of variable by repeating group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Enumeration-of-variable-by-repeating-group/m-p/893158#M82921</link>
      <description>&lt;P&gt;Amazing, thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 13:26:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Enumeration-of-variable-by-repeating-group/m-p/893158#M82921</guid>
      <dc:creator>chsprogramming</dc:creator>
      <dc:date>2023-09-07T13:26:53Z</dc:date>
    </item>
  </channel>
</rss>

