BookmarkSubscribeRSS Feed
paul2877
Calcite | Level 5

I have table1 and table2

 

Trying to do a left join from Table1 to Table2

 

In table1 the key is Lamb

in table2 the key is Mary,had,a,Little,Lamb in one column

 

I want to join these tables on a key where table1 key matches the partial string in Table2. I want to bring back te results if Lamb is anywhere in the key.

 

Thanks,

 

paul

2 REPLIES 2
ballardw
Super User

Really should provide some idea of the structure/contents of both tables and what the desired output may be.

 

Is something like this what your are looking for:

data table1;
   input word $;
datalines;
lamb
Lamb
sheep
cow
;
run;

data table2;
   key=  "Mary,had,a,Little,Lamb";output;
   key=  "Sheep are not cows";output;
run;

proc sql;
   select table1.*, table2.*
   from table1, table2
   where index(table2.key,strip(table1.word))>0;
quit;
Astounding
PROC Star

Details will be important.  For example:

 

Does capitalization matter?

 

Partial words: 

 

Does this contain Lamb:  Lambaste,the,cowards

 

Does this contain sheep:  shy,sheepish,timid

 

Does this contain sheep:  wolf-in-sheep's-clothing

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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