<?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: adding a counter to a data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/adding-a-counter-to-a-data-set/m-p/620326#M182256</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13712"&gt;@GreggB&lt;/a&gt;&amp;nbsp; Not sure of your objective, do you mean append as combine??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

Data  one;
input (first  last) (:$10.)   UID;
cards;
tom        jones           1
elvis       pressley       2
frank       sinatra         3 
;


data two;
input (first        last) (:$10.);
cards;
Ella        Fitzgerald
Doris      Day
;

data want;
 set one two(in=b);
  if b then uid=_iorc_+1;
 _iorc_=uid;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 27 Jan 2020 20:23:48 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-01-27T20:23:48Z</dc:date>
    <item>
      <title>adding a counter to a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-a-counter-to-a-data-set/m-p/620318#M182250</link>
      <description>&lt;P&gt;Data set one:&lt;/P&gt;
&lt;P&gt;first&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; last&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; UID&lt;/P&gt;
&lt;P&gt;tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jones&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;elvis&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pressley&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;frank&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sinatra&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data set two:&lt;/P&gt;
&lt;P&gt;first&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; last&lt;/P&gt;
&lt;P&gt;Ella&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Fitzgerald&lt;/P&gt;
&lt;P&gt;Doris&amp;nbsp; &amp;nbsp; &amp;nbsp; Day&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to combine the 2 data sets and start assigning the UID where data set one leaves off. So, Ella has UID = 4 , Doris has UID = 5&amp;nbsp; and so on.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 20:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-a-counter-to-a-data-set/m-p/620318#M182250</guid>
      <dc:creator>GreggB</dc:creator>
      <dc:date>2020-01-27T20:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: adding a counter to a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-a-counter-to-a-data-set/m-p/620326#M182256</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13712"&gt;@GreggB&lt;/a&gt;&amp;nbsp; Not sure of your objective, do you mean append as combine??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

Data  one;
input (first  last) (:$10.)   UID;
cards;
tom        jones           1
elvis       pressley       2
frank       sinatra         3 
;


data two;
input (first        last) (:$10.);
cards;
Ella        Fitzgerald
Doris      Day
;

data want;
 set one two(in=b);
  if b then uid=_iorc_+1;
 _iorc_=uid;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Jan 2020 20:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-a-counter-to-a-data-set/m-p/620326#M182256</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-27T20:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: adding a counter to a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-a-counter-to-a-data-set/m-p/620333#M182262</link>
      <description>&lt;P&gt;I would use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set one two(in=b);
  if b then uid=_n_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or even simpler&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set one two;
 uid=_n_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; can you explain how using _iorc_ works here? I wouldn't normally think of using it except to check the status of an I/O operation for errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13712"&gt;@GreggB&lt;/a&gt; are the UID numbers in data set ONE always consecutive integers starting with 1?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 20:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-a-counter-to-a-data-set/m-p/620333#M182262</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-27T20:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: adding a counter to a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-a-counter-to-a-data-set/m-p/620341#M182268</link>
      <description>&lt;P&gt;Just like any other freely available variable in a process like you said if and only if when we are not using any I/O operations otherwise _N_ is rather a safe bet.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The advantage i find in _iorc_ is automatic retain across datastep iterations as opposed to _n_ and i have gotten used to it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So Auto retain and auto drop = lazy me&amp;nbsp; a done deal &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 21:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-a-counter-to-a-data-set/m-p/620341#M182268</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-27T21:03:40Z</dc:date>
    </item>
  </channel>
</rss>

