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.
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;
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;
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?
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 🙂
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.