Reputation: 13
Working code:
data t2;
set t1;
where a like "%SR";
run;
Code errored:
data t2;
set t1;
if a like "%SR";
run;
Error message:
ERROR 388-185: Expecting an arithmetic operator.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
It complained about 'like'
Any ideal?
Upvotes: 1
Views: 449
Reputation: 27508
The LIKE
operator is not understood by the DATA Step IF
statement.
LIKE
is available to DATA Step in the WHERE
statement, the WHERE=
data set option, or PROC SQL WHERE
clause.
data have;
input text $CHAR20.;
datalines;
ABCEFG
YESSR
Mark JR
Mark SR
;
data want;
set have;
where text like '%SR'; /* where statement */
run;
data want;
set have(where=(text like '%SR')); /* where= option */
run;
proc sql;
create table want as
select text from have
where text like '%SR' /* where clause */
;
Upvotes: 0
Reputation: 51566
LIKE is not an operator that SAS code understands. The only reason it works in WHERE is because WHERE statement supports SQL syntax such as LIKE and BETWEEN to make it easier to push the WHERE condition into a remote database.
Use some other way to test if the last two letters are SR. Here are two methods.
if 'SR' = substrn(a,length(a)-1);
if 'RS' =: left(reverse((a)) ;
Upvotes: 3