Hello team,
I want to Left join two datasets by a variable, which that variable is part of the other variable from left table.
data LeftTable; input plan_des: $15 registered; datalines; plan blue 12 Florida commerce plan 14 Florida plan ABC ; Run data right Table; input plan_des: $15 registered; datalines; plan 15 commerce 14 ABC ; Run
The right dataset has only some part of the string from the left dataset. If we want to join them by plan_des, how can we do that?
Regards,
Blue Blue
SQL is your best bet here. One way:
from LEFT left join RIGHT on LEFT.PLAN_DES like cats('%', RIGHT.PLAN_DES, '%')
Another way:
from LEFT left join RIGHT on index(LEFT.PLAN_DES,strip(RIGHT.PLAN_DES))
You may want to use the search function to get some solutions on how to join by partial match. You could use proc sql and index or find to in the where statement.
SQL is your best bet here. One way:
from LEFT left join RIGHT on LEFT.PLAN_DES like cats('%', RIGHT.PLAN_DES, '%')
Another way:
from LEFT left join RIGHT on index(LEFT.PLAN_DES,strip(RIGHT.PLAN_DES))
@GN0001 - Posting incomplete code plus error messages that don't relate to the code isn't helpful.
Please post your complete SAS log including code, notes and errors and use the Insert Code icon (</>) to ensure the formatting isn't mucked up.
@GN0001 - Is that because it is confidential? If so just make up a similar example using made-up data or one of SAS's sample tables in the SASHELP library.
Your posted code seems to be for different datasets than your original post.
Use FIND() or FINDW() function because the support the trim and ignore case options. The difference is whether you want to match when the smaller string is part of a larger word or only when it matches a full word in the larger string.
...
from table b
left join a
on upcase(a.diagcode) = upcase(b.diagcode)
and upcase(a.subdiagcod)=upcase(b.subdiagcode)
and findw(a.plan,b.plan,,'it')
...
data LeftTable; input plan_des & $35. registered; datalines; plan blue 12 Florida commerce plan 14 Florida plan ABC . ; Run; data rightTable; input plan_des: $15. registered; datalines; plan 15 commerce 14 BC . ; Run; proc sql; select a.*,b.registered as b_registered from lefttable as a left join righttable as b on a.plan_des contains strip(b.plan_des); quit;
Hello,
How do you know which characters are stripped off?
Regards,
Blue Blue
Function findw() ?
proc sql; select a.*,b.registered as b_registered from lefttable as a left join righttable as b on findw( a.plan_des ,strip(b.plan_des)); quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.