BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GreggB
Pyrite | Level 9

Data set one:

first        last            UID

tom        jones           1

elvis       pressley       2

frank       sinatra         3 

 

Data set two:

first        last

Ella        Fitzgerald

Doris      Day

 

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  and so on. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @GreggB  Not sure of your objective, do you mean append as combine??

 



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;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Hi @GreggB  Not sure of your objective, do you mean append as combine??

 



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;
PaigeMiller
Diamond | Level 26

I would use

 

data want;
 set one two(in=b);
  if b then uid=_n_;
run;

 

or even simpler

 

data want;
 set one two;
 uid=_n_;
run;

 

@novinosrin 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.

 

@GreggB are the UID numbers in data set ONE always consecutive integers starting with 1?

--
Paige Miller
novinosrin
Tourmaline | Level 20

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. 

The advantage i find in _iorc_ is automatic retain across datastep iterations as opposed to _n_ and i have gotten used to it. 

So Auto retain and auto drop = lazy me  a done deal 🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1265 views
  • 0 likes
  • 3 in conversation