BookmarkSubscribeRSS Feed
MARS
Calcite | Level 5
Can some please help me on following issue.

I want to merge two sas datasets to create a new data set.

However, I only need to few specific variables from the second data set to be included in the new merged data set.

Can somebody tell me the SAS-CODE to use for this purpose i.e two include only specific variables from one data set in the merge step.

(Please not that I have very huge data sets)
2 REPLIES 2
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Mars,

These are two common approaches to your problem:
a) with a datastep (d1 and d2 should be sorted by X before merging):
data c;
merge d1(in=d1ind) d2(keep=X A B);
if d1ind;
by X;
run;
a) with proc SQL:
proc SQL;
create table c as
select a.*, b.A, b.B
from d1 as a left join d2 as b on a.X=b.X
;quit;
Sincerely,
SPR
MARS
Calcite | Level 5
Thanks

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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