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
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 ;
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!
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.