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 🙂

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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