10-04-2016 06:55 PM
I need to compare data to one variable to modify other.
IF VAR1 = 0 THEN VAR2 ='STATUS0';
Last sas code works the but not like when I need to compare a string
IF VAR1 like '%zero%' THEN VAR2 ='STATUS0';
this code does not work because IF command does not recognize the LIKE function
IF VAR1 like 0 THEN VAR2 ='STATUS0';
ERROR 388-185: Expecting an arithmetic operator.
what can I do?
10-04-2016 06:57 PM
LIKE is not a valid SAS function, except in WHERE or SQL.
Look at using either the FINDW or INDEXW functions instead that will search the string for zero. Note that the search is case sensitive so you may want to use a modifier that ignores case.
10-04-2016 09:52 PM
Or use SQL :
proc sql; create table data2 as select VAR1, .... , case when VAR1 like '%zero%' THEN 'STATUS0' else VAR2 end as VAR2 from DATA1; quit;
10-04-2016 09:58 PM
Or use two WHERE clauses in a data step
data data2; set DATA1 (where=(VAR1 like '%zero%') in=isZero) DATA1 (where=(VAR1 not like '%zero%')); if isZero then VAR2 = 'STATUS0'; run;
10-05-2016 02:02 AM
ERROR 388-185: Expecting an arithmetic operator
makes me think that your variable VAR1 is a numeric variable, and therefore using the like operator (which is for character values) makes no sense.