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

Got a data set merging problem:

Data Have1;

a1a2a3
.43
1..
234
493
952

 

data have2;

a1b1b2
165
24.
923
1211

I want to merge data Have1 and Have2 in such a way that if the values of the variable a1 in Have1 match with values of a1 in Have2 then keep otherwise drop. For example I want the new set like:

a1a2 a3b1b2
1..65
2344.
95223

 

I would appreciate very much if any expert out there help me out to get the result.

 

Thank you very much.

Sijansap

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
r_behata
Barite | Level 11
data want;
merge have1(in=a) have2(in=b);
by a1;
if a and b;
run

 

View solution in original post

5 REPLIES 5
r_behata
Barite | Level 11
data want;
merge have1(in=a) have2(in=b);
by a1;
if a and b;
run

 

sijansap
Obsidian | Level 7
Thank you r_behata.
Your codes were short and simple and worked just the way I wanted.
singhsahab
Lapis Lazuli | Level 10

Hello,

 

here is an alternative method :

 

data want;
if 0 then set have2;
if _n_=1 then do;
declare hash h1(dataset:'have2');
h1.definekey('a1');
h1.definedata(all:'y');
h1.definedone();
end;
set have1;
 r1=h1.find(key:a1);
 if r1=0;
 drop r1;
run; 

Thanks 🙂 

sijansap
Obsidian | Level 7
This works well when there are repeated values of a1 in Have1. Thank you KurtBremser.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1337 views
  • 4 likes
  • 4 in conversation