I need to compare data to one variable to modify other.
For example:
data data2;
set data1;
IF VAR1 = 0 THEN VAR2 ='STATUS0';
RUN;
Last sas code works the but not like when I need to compare a string
data data2;
set data1;
IF VAR1 like '%zero%' THEN VAR2 ='STATUS0';
RUN;
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?
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.
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;
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;
(untested)
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.
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.