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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.