<?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: add a row number to a data set  by multiple groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543023#M150099</link>
    <description>&lt;P&gt;Thank you for your reply.&lt;/P&gt;
&lt;P&gt;You created to series of sequential number.&lt;/P&gt;
&lt;P&gt;However, I want to create only one series that will get following numbers(related to ID+date):&lt;/P&gt;
&lt;P&gt;1&lt;BR /&gt;2&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;1&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;1&lt;BR /&gt;2&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Mar 2019 06:18:20 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2019-03-14T06:18:20Z</dc:date>
    <item>
      <title>add a row number to a data set  by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543016#M150093</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;I want to add a new field (column) of sequential &amp;nbsp;number by multiple groups.&lt;BR /&gt;The code that I wrote is not working well because the&amp;nbsp;sequential &amp;nbsp;numbers should be related to ID+date and not only to ID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data aaa;
attrib
ID length = 8 format=best8. informat = best8.
date length = 8  format =DDMMYY10. informat = DDMMYY10.
SaleAmount length = 8 format=best8. informat = best8.;
INPUT ID date SaleAmount;
cards;
1 1/1/2011 100
1 1/1/2011 50
1 5/1/2011 150
1 5/1/2011 51300
1 3/4/2011 200
2 5/1/2010 300
2 5/1/2010 290
2 5/1/2010 310
2 6/3/2010 40
2 6/3/2010 45
;
run;
proc sort data=aaa;by ID date;Run;
data bbb;  
set aaa;
by ID date;
if first.ID and first.date then seq_id=0;
seq_id+1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Mar 2019 05:49:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543016#M150093</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-03-14T05:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: add a row number to a data set  by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543018#M150095</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data aaa;
attrib
ID length = 8 format=best8. informat = best8.
date length = 8  format =DDMMYY10. informat = DDMMYY10.
SaleAmount length = 8 format=best8. informat = best8.;
INPUT ID date SaleAmount;
cards;
1 1/1/2011 100
1 1/1/2011 50
1 5/1/2011 150
1 5/1/2011 51300
1 3/4/2011 200
2 5/1/2010 300
2 5/1/2010 290
2 5/1/2010 310
2 6/3/2010 40
2 6/3/2010 45
;
run;
proc sort data=aaa;by ID date;Run;

data how_does_first_dot_work;
   format first_id first_date;
   set aaa;
   by id date;
   first_id=first.id;
   first_date=first.date;
run;

data want;
   format seq_id seq_date;
   set aaa;
   by id date;
   if first.id then seq_id=0;
   if first.date then seq_date=0;
   seq_id+1;
   seq_date+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is one of the seq* variables in data want what you're looking for?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 05:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543018#M150095</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-03-14T05:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: add a row number to a data set  by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543023#M150099</link>
      <description>&lt;P&gt;Thank you for your reply.&lt;/P&gt;
&lt;P&gt;You created to series of sequential number.&lt;/P&gt;
&lt;P&gt;However, I want to create only one series that will get following numbers(related to ID+date):&lt;/P&gt;
&lt;P&gt;1&lt;BR /&gt;2&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;1&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;1&lt;BR /&gt;2&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 06:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543023#M150099</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-03-14T06:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: add a row number to a data set  by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543026#M150101</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data aaa;
attrib
ID length = 8 format=best8. informat = best8.
date length = 8  format =DDMMYY10. informat = DDMMYY10.
SaleAmount length = 8 format=best8. informat = best8.;
INPUT ID date SaleAmount;
cards;
1 1/1/2011 100
1 1/1/2011 50
1 5/1/2011 150
1 5/1/2011 51300
1 3/4/2011 200
2 5/1/2010 300
2 5/1/2010 290
2 5/1/2010 310
2 6/3/2010 40
2 6/3/2010 45
;
run;
proc sort data=aaa;by ID date;Run;
data bbb;  
set aaa;
by ID date;
if first.date then seq_id=0;
seq_id+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Mar 2019 06:25:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543026#M150101</guid>
      <dc:creator>DanielLangley</dc:creator>
      <dc:date>2019-03-14T06:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: add a row number to a data set  by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543030#M150105</link>
      <description>&lt;P&gt;It is perfect solution.&lt;/P&gt;
&lt;P&gt;I just dont understand.&lt;/P&gt;
&lt;P&gt;Both ID and date define the "group".&lt;/P&gt;
&lt;P&gt;Why do you write "if first.date" and not &amp;nbsp;"if first.date and first.ID?&lt;/P&gt;
&lt;P&gt;Why do you write "if first.date" and not &amp;nbsp;"if first.ID?&lt;/P&gt;
&lt;P&gt;May you please explain?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 06:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543030#M150105</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-03-14T06:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: add a row number to a data set  by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543031#M150106</link>
      <description>&lt;P&gt;You have grouped the dataset by id and then all of the rows with the same id are further broken down by date. So first.id is always the start of a new id group and first.date is always the start of a new date within that idgroup.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It might be worth assigning variables to equal the first.id and first date to see how it is working exactly. Hope this makes sense. If it doesn't I'll try and create a suitable example when I'm at a computer.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 06:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543031#M150106</guid>
      <dc:creator>DanielLangley</dc:creator>
      <dc:date>2019-03-14T06:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: add a row number to a data set  by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543033#M150108</link>
      <description>&lt;P&gt;Did you even look at the results of what I posted?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 06:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-a-row-number-to-a-data-set-by-multiple-groups/m-p/543033#M150108</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-03-14T06:42:54Z</dc:date>
    </item>
  </channel>
</rss>

