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

Hi,

 

I have a query where i am using the  if statement and i need to find the string matching the variable given.

 

if lead_status in ( '%APPROVED',

'%APPROVAL PENDING',

'%SEND TO SALES',

''

      )

 

And this not reading or working...!

This is in a data step!.

 

Appreciate your help and genuine support

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Either modify your program logic so that you can use a WHERE statement instead of an IF statement.

where (x like '%xxx') or (x like '%yyy') ;

Or use some other method to test the values in your IF statement.

Perhaps you can use PRXMATCH() function instead?

 

Editor's Note: 

As Reeza noted, the like function is not available for IF conditions, but  rather for WHERE statements. Also including Ksharp's example of PRXMATCH() syntax:

if prxmatch('/APPROVED$|APPROVAL PENDING$|SEND TO SALES$/i',strip(lead_status));

 

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

Either modify your program logic so that you can use a WHERE statement instead of an IF statement.

where (x like '%xxx') or (x like '%yyy') ;

Or use some other method to test the values in your IF statement.

Perhaps you can use PRXMATCH() function instead?

 

Editor's Note: 

As Reeza noted, the like function is not available for IF conditions, but  rather for WHERE statements. Also including Ksharp's example of PRXMATCH() syntax:

if prxmatch('/APPROVED$|APPROVAL PENDING$|SEND TO SALES$/i',strip(lead_status));

 

codyV
Fluorite | Level 6
How can i use it in a if statement ? even if i use a where!
Reeza
Super User
LIKE is not a valid function in an IF statement. You cannot use that function in an IF statement. You can use it in a WHERE statement.

Similar functions that you could use in an IF statement are FIND(), FINDW(), INDEX/W() and Regex.
Ksharp
Super User
if prxmatch('/APPROVED$|APPROVAL PENDING$|SEND TO SALES$/i',strip(lead_status));

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 34259 views
  • 2 likes
  • 4 in conversation