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

Now I have 2 tables,

 

Data table1

column1column2
AE1
AAE2
A5

and reference table 2

column1column2
AE1,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.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

So you want to flag the two first records, correct?

jyu068
Calcite | Level 5
hi I want to flag the rows in t1 which column1 has the same value as t2.column1 and t1 column2's value is one of the t2 column2 value.
Thanks
PeterClemmensen
Tourmaline | Level 20

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;
Astounding
PROC Star

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.

Tom
Super User Tom
Super User

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. 

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!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 839 views
  • 2 likes
  • 4 in conversation