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

 

Hi,

 

I've 2 datasets which has 6 columns in 1 dataset & another has 8 columns. But first 5 columns are same in both. Say first dataset name is A and another B. I want to merge the 2 dataset such that I get 9 total columns. Generally we merge using SQL in the following way:

 

 

proc sql;
create table example as
select a.*,b.var1,b.var2,b.var3
from A as a left join B as b
on a.key1 = b.key1 and a.key2 = b.key2 and a.key3 = b.key3 and a.key4 = b.key4 and a.key5 = b.key5;
quit;

And if I need to merge the table again and again, I've to repeatedly write the 5 keys again and again.

 

My question is, is there any way I can pass the key in macro and call the macro while merging? 

 

Thanks!

1 ACCEPTED SOLUTION
4 REPLIES 4
Reeza
Super User

Try a Natural JOIN instead.

newbie_ari
Fluorite | Level 6
@Reeza: Thanks for your reply. But could you please elaborate on what you mean by natural join.
newbie_ari
Fluorite | Level 6
@Reeza: Thanks a lot! Your answer was so uncommon I didn't bother to google it. I thought you wrote something wrong. I'm working on SQL for quite sometime & had the impression that I know SQL pretty well. But life has it's own way to show you your limitations & keeps you humble. Thanks again!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 4 replies
  • 1027 views
  • 1 like
  • 2 in conversation