<?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 the same number to obs within the same group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assign-the-same-number-to-obs-within-the-same-group/m-p/793061#M254130</link>
    <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I have a dataset that is grouped by a variable 'group':&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;id group
1 a
2 a
3 a
4 b
5 b 
6 b
7 c
8 c
9 d
10 d
11 d
12 d
13 d&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to create a serial number that assigns the same number to obs within the same group:&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;id group number
1 a 1
2 a 1
3 a 1
4 b 2
5 b 2
6 b 2
7 c 3
8 c 3
9 d 4
10 d 4 
11 d 4
12 d 4
13 d 4&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;```&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 28 Jan 2022 04:44:05 GMT</pubDate>
    <dc:creator>roroholic123</dc:creator>
    <dc:date>2022-01-28T04:44:05Z</dc:date>
    <item>
      <title>Assign the same number to obs within the same group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-the-same-number-to-obs-within-the-same-group/m-p/793061#M254130</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I have a dataset that is grouped by a variable 'group':&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;id group
1 a
2 a
3 a
4 b
5 b 
6 b
7 c
8 c
9 d
10 d
11 d
12 d
13 d&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to create a serial number that assigns the same number to obs within the same group:&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;id group number
1 a 1
2 a 1
3 a 1
4 b 2
5 b 2
6 b 2
7 c 3
8 c 3
9 d 4
10 d 4 
11 d 4
12 d 4
13 d 4&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;```&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 28 Jan 2022 04:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-the-same-number-to-obs-within-the-same-group/m-p/793061#M254130</guid>
      <dc:creator>roroholic123</dc:creator>
      <dc:date>2022-01-28T04:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Assign the same number to obs within the same group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-the-same-number-to-obs-within-the-same-group/m-p/793062#M254131</link>
      <description>&lt;P&gt;how about this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id group $;
datalines;
1 a
2 a
3 a
4 b
5 b 
6 b
7 c
8 c
9 d
10 d
11 d
12 d
13 d
;
run;
proc sort data=have;
  by id group;
run;
data want;
  set have;
  by id group;
  retain number;
  if not(group=lag(group)) then number+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 04:58:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-the-same-number-to-obs-within-the-same-group/m-p/793062#M254131</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-01-28T04:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Assign the same number to obs within the same group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-the-same-number-to-obs-within-the-same-group/m-p/793064#M254133</link>
      <description>Thank you!!!&lt;BR /&gt;</description>
      <pubDate>Fri, 28 Jan 2022 05:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-the-same-number-to-obs-within-the-same-group/m-p/793064#M254133</guid>
      <dc:creator>roroholic123</dc:creator>
      <dc:date>2022-01-28T05:04:16Z</dc:date>
    </item>
  </channel>
</rss>

