BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5

data ex;
name='kumar(ex)' ;
output;
name='shiva' ;
output;
if name ^=:'(ex)' then rank=1;
else if name =:'(ex)' then rank=2;
run;

 

how to use like and not like operations in if statement

2 REPLIES 2
Astounding
PROC Star
The syntax is fine, but the logic is faulty. RANK will be missing because the program outputs observations before assigning a value to RANK.
ballardw
Super User

It a data step LIKE , as you intend to use it, is only available with WHERE, not if.

 

In a data step you can use other functions to identify the presence of a sequence of characters as part of the values such as INDEX or FIND. If you have more complex pattern then PRXMATCH perhaps.

The Index and Find functions return the position of found value or 0 if not found.

Notice the use of datalines to provide values and the different results for Find with and without the 'i', case insensitive, comparison.

data ex;
   input name :$15.;
   /* checks for presence of ex anywhere in name*/
   if find(name,'ex')=0 then rank=1;
   else rank=2;
   /* presence of ex case insensitive*/
   if find(name,'ex','i')=0 then rank2=1;
   else rank2=2;

datalines;
kumar(ex)
shiva
jonhEXfg
mareXbo
PATExxxx
;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1206 views
  • 3 likes
  • 3 in conversation