Now I have 2 tables,
Data table1
column1 | column2 |
A | E1 |
A | AE2 |
A | 5 |
and reference table 2
column1 | column2 |
A | E1,AE2,3 |
what I want to implement is to create a matching flag calculation like the code below:
case
when t1.column1 = t2.column1 and t1.column2 in t2.column2
then 1
else 0
end
but it has a syntax error. any suggestions?
Thanks.
Try this
data a;
input column1 $ column2 $;
datalines;
A E1
A AE2
A 5
;
data b;
input column1 $ column2 $;
datalines;
A E1,AE2,3
;
data c;
merge a b (rename=column2=column3);
by column1;
dummy = indexw(column3, trim(column2), ',') > 0;
run;
So you want to flag the two first records, correct?
Try this
data a;
input column1 $ column2 $;
datalines;
A E1
A AE2
A 5
;
data b;
input column1 $ column2 $;
datalines;
A E1,AE2,3
;
data c;
merge a b (rename=column2=column3);
by column1;
dummy = indexw(column3, trim(column2), ',') > 0;
run;
Your table 2 isn't a reference table. It's a nightmare.
The programming cam be done, but you need to do it each time you want to use the reference table. Instead of that, convert table2 so that it has the same format as table 1. That will simplify the matching process and make it very flexible. Merging, hashing, formats all become possible techniques with a better structure for the reference table.
IN operator is for test a series of values, not search in a string.
Use the INDEXW() function (or FINDW() function) to check if a word exists in a delimited string.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.