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

Hello, I would like to ask a question on SET statements when used to combine tables.

 

I have got two tables which I am trying to combine:

 

Table Global

EmployeeID Name Location
1 A Global
2 B Global
3 C Global

 

Table Local

EmployeeID Name Location Gender
1 A Europe M
2 B Asia F
3 C Africa M

 

I want to use SET statements:

 

 

DATA Combined;
	SET Global Local; 
RUN;

 

 

That gives:

 

EmployeeID Name Location Gender
1 A Global M
1 A Europe  
2 B Global F
2 B Asia  
3 C Global M
3 C Africa  

 

 

What I wanted to find out is if I can get the below results still using SET statements:

 

EmployeeID Name Location Gender
1 A Global M
1 A Europe M
2 B Global F
2 B Asia F
3 C Global M
3 C Africa M

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Try this:

data combined;
set
  local (rename=(gender=_gender))
  global
;
by employeeid;
retain gender;
if first.employeeid then gender = _gender;
drop _gender;
run;

Or, shorter:

 

data combined;
set
  local
  global
;
by employeeid;
gender = ifc(first.employeeid,gender,lag(gender));
run;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Try this:

data combined;
set
  local (rename=(gender=_gender))
  global
;
by employeeid;
retain gender;
if first.employeeid then gender = _gender;
drop _gender;
run;

Or, shorter:

 

data combined;
set
  local
  global
;
by employeeid;
gender = ifc(first.employeeid,gender,lag(gender));
run;
Zatere
Quartz | Level 8

Thanks a lot! I learnt something new. I was hoping though not to have to sort the data.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1023 views
  • 0 likes
  • 2 in conversation