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 ;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.
Ready to level-up your skills? Choose your own adventure.