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

Hi Guys, 

I need to merge two datasets by a variable that is included in other variable in the second dataset.

for example: 

 

dataset#1

namesdata
ABLIM1 ABLIM KIAA0059 LIMAB1data1 
AK3 AK3L1 AK6 AKL3Ldata2
AK4 AK3 AK3L1data3
ADD3 ADDLdata4
PHYKPL AGXT2L2 PP9286data5

 

 

dataset#2

namemore data
ABLIMmore data 1
ADDLmore data 2
DKGmore data 3
PRWRmore data 4

 

 

 

The result I need:

namenamesdatamore data
ABLIMABLIM1 ABLIM KIAA0059 LIMAB1data1 more data 1
ADDLADD3 ADDLdata4more data 2
DKG  more data 3
PRWR  more data 4

 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data one;
input names & $50.	data $20.;
cards;
ABLIM1 ABLIM KIAA0059 LIMAB1	data1 
AK3 AK3L1 AK6 AKL3L	  data2
AK4 AK3 AK3L1	 data3
ADD3 ADDL	  data4
PHYKPL AGXT2L2 PP9286	 data5
;

data two;
input name $	more_data & $15.;
cards;
ABLIM	more data 1
ADDL	more data 2
DKG	more data 3
PRWR	more data 4
;

proc sql;
create table want as
select a.*,b.names,data
from two a left join one b
on b.names contains strip(a.name);
quit;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
data one;
input names & $50.	data $20.;
cards;
ABLIM1 ABLIM KIAA0059 LIMAB1	data1 
AK3 AK3L1 AK6 AKL3L	  data2
AK4 AK3 AK3L1	 data3
ADD3 ADDL	  data4
PHYKPL AGXT2L2 PP9286	 data5
;

data two;
input name $	more_data & $15.;
cards;
ABLIM	more data 1
ADDL	more data 2
DKG	more data 3
PRWR	more data 4
;

proc sql;
create table want as
select a.*,b.names,data
from two a left join one b
on b.names contains strip(a.name);
quit;

efi88
Fluorite | Level 6

Thank you so much!

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!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 547 views
  • 1 like
  • 2 in conversation