<?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 continuing the counter when adding more obs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/continuing-the-counter-when-adding-more-obs/m-p/642739#M191786</link>
    <description>&lt;P&gt;I created a UID in my data set like so:&lt;/P&gt;
&lt;PRE&gt;data two;
set one;
UID + 1;
run;&lt;/PRE&gt;
&lt;P&gt;the last record is:&lt;/P&gt;
&lt;P&gt;name&amp;nbsp; &amp;nbsp; UID&lt;/P&gt;
&lt;P&gt;Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;899&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a new data set named &lt;STRONG&gt;new_students&lt;/STRONG&gt; like so:&lt;/P&gt;
&lt;P&gt;name&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;**bleep**&lt;/P&gt;
&lt;P&gt;Harry&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;I want to add these records to data set&lt;STRONG&gt; two&lt;/STRONG&gt; to get this result:&lt;/P&gt;
&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp; UID&lt;/P&gt;
&lt;P&gt;Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;899&lt;/P&gt;
&lt;P&gt;**bleep**&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;900&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Harry&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 901&lt;/P&gt;
&lt;P&gt;etc&lt;/P&gt;</description>
    <pubDate>Fri, 24 Apr 2020 18:20:42 GMT</pubDate>
    <dc:creator>GreggB</dc:creator>
    <dc:date>2020-04-24T18:20:42Z</dc:date>
    <item>
      <title>continuing the counter when adding more obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/continuing-the-counter-when-adding-more-obs/m-p/642739#M191786</link>
      <description>&lt;P&gt;I created a UID in my data set like so:&lt;/P&gt;
&lt;PRE&gt;data two;
set one;
UID + 1;
run;&lt;/PRE&gt;
&lt;P&gt;the last record is:&lt;/P&gt;
&lt;P&gt;name&amp;nbsp; &amp;nbsp; UID&lt;/P&gt;
&lt;P&gt;Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;899&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a new data set named &lt;STRONG&gt;new_students&lt;/STRONG&gt; like so:&lt;/P&gt;
&lt;P&gt;name&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;**bleep**&lt;/P&gt;
&lt;P&gt;Harry&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;I want to add these records to data set&lt;STRONG&gt; two&lt;/STRONG&gt; to get this result:&lt;/P&gt;
&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp; UID&lt;/P&gt;
&lt;P&gt;Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;899&lt;/P&gt;
&lt;P&gt;**bleep**&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;900&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Harry&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 901&lt;/P&gt;
&lt;P&gt;etc&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 18:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/continuing-the-counter-when-adding-more-obs/m-p/642739#M191786</guid>
      <dc:creator>GreggB</dc:creator>
      <dc:date>2020-04-24T18:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: continuing the counter when adding more obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/continuing-the-counter-when-adding-more-obs/m-p/642743#M191789</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Existing sample with uid*/
data one;
 set sashelp.class;
 uid+1;
run;
/*Read the last uid and store in a macro var*/
data _null_;
 set one nobs=nobs point=nobs;
 call symputx('uid',uid,'g');
 stop;
run;
/*write to the log to check the value to help debug if any*/
%put &amp;amp;=uid;
/*Increment the counter for two using uid macro var*/
data two;
 set sashelp.class;
 retain uid &amp;amp;uid;
 uid+1;
run;
/*append two to one*/
proc append base=one data=two;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Apr 2020 18:41:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/continuing-the-counter-when-adding-more-obs/m-p/642743#M191789</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-04-24T18:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: continuing the counter when adding more obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/continuing-the-counter-when-adding-more-obs/m-p/642782#M191803</link>
      <description>&lt;P&gt;If you don't mind using undocumented SAS features:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data oldData;
do name = "Georges", "Henry", "Paul";
	UID + 1;
	output;
	end;
run;

data newData;
do name = "Loretta", "Mary", "Suzy";
	output;
	end;
run;

proc sql;
select max(UID) into : maxUID from oldData;
insert into oldData (UID, name)
select &amp;amp;maxUID + monotonic(), name from newData;
quit;

proc print data=oldData; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs. 	name 	UID
1 	Georges 1
2 	Henry 	2
3 	Paul 	3
4 	Loretta 4
5 	Mary 	5
6 	Suzy 	6&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Apr 2020 20:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/continuing-the-counter-when-adding-more-obs/m-p/642782#M191803</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-04-24T20:31:39Z</dc:date>
    </item>
  </channel>
</rss>

