0
votes

I have a query I am trying to run and I want to filter by multiple conditions but I cant seem to find a way to do so here is my code:

WHERE (AL1.X_ult=AL6.X_ult)  

AND (AL1.X_number LIKE '%123456789'
AND AL1.X_number LIKE '%1234567882'

I am new to SAS and I am wondering how can I use LIKE to filter by more than one condition or is their another operator I should use instead, because when I run just:

WHERE (AL1.X_ult=AL6.X_ult)  

AND (AL1.X_number LIKE '%123456789'

it runs fine, but I want to filter down by multiple numbers like

WHERE (AL1.X_ult=AL6.X_ult)  

AND (AL1.X_number LIKE '%123456789'
AND AL1.X_number LIKE '%1234567882'
AND AL1.X_number LIKE '%1234534882'
AND AL1.X_number LIKE '%1234512882'
AND AL1.X_number LIKE '%1234586882'
AND AL1.X_number LIKE '%1233921882'

any help would be greatly appreciated, also something to note their will be multiple numbers in my LIKE that match those 9 digit numbers so I want to pull in all of the numbers that have those digits in them.

1

1 Answers

1
votes

Seems like you need "OR" there?

WHERE (AL1.X_ult=AL6.X_ult)  
AND (AL1.X_number LIKE '%123456789'
OR AL1.X_number LIKE '%1234567882'
OR AL1.X_number LIKE '%1234534882'
OR AL1.X_number LIKE '%1234512882'
OR AL1.X_number LIKE '%1234586882'
OR AL1.X_number LIKE '%1233921882')

You can get some of these in the same like :

WHERE (AL1.X_ult=AL6.X_ult)  
AND (AL1.X_number LIKE '%123456789'
OR AL1.X_number LIKE '%12345%882'
OR AL1.X_number LIKE '%1233921882')

but it depends on whether there are other with that pattern you don't want...

Regular expressions are the next 'level up' for this sort of thing, but they still require you having some logical pattern.