DATA Step, Macro, Functions and more

LIKE '%' does not work

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 131
Accepted Solution

LIKE '%' does not work

Hi,

I intend to select those cases which satisfy:

IF regno LIKE ('M%15', 'M%25', 'M%30', 'DISC') THEN OUTPUT;

However, this code is wrong.

How can I accomplish this? Thanks a lot.


Accepted Solutions
Solution
‎03-14-2012 01:28 PM
Trusted Advisor
Posts: 1,301

LIKE '%' does not work

The like operator is not available to the if statement only where clauses also I am quite sure it cannot be combined with the in operator to have a list of values.

View solution in original post


All Replies
Super User
Posts: 19,837

LIKE '%' does not work

You can only use LIKE in a WHERE clause not an if.

Solution
‎03-14-2012 01:28 PM
Trusted Advisor
Posts: 1,301

LIKE '%' does not work

The like operator is not available to the if statement only where clauses also I am quite sure it cannot be combined with the in operator to have a list of values.

Super User
Posts: 10,041

LIKE '%' does not work

An alternative way is to use perl regular expression.

IF prxmatch('/M.*15|M.*25|M.*30|DISC/',regno) THEN OUTPUT;

Ksharp

New Contributor
Posts: 2

Re: LIKE '%' does not work

For what it's worth, I found that using CASE within a PROC SQL SELECT statement worked for me. Sharing the example code in case it is useful.

PROC SQL;
CREATE TABLE SET_A AS

SELECT *, (CASE

                    WHEN FIELD LIKE 'APPL%' THEN 'A'

                    WHEN FIELD LIKE 'SYS%' THEN 'B'

                    ELSE ''

               END

               )

               AS NEW_FIELDNAME

FROM SOURCE_TABLE

WHERE OTHER_CRITERIA = 'XXX';

RUN;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 262 views
  • 3 likes
  • 5 in conversation