Reputation: 123
The following code is generating the above error. I'm looking for an explanation. Please help.
%GLOBAL var;
%LET var = 1;
%MACRO test;
%IF &var. in (1,2) %THEN %DO;
%PUT &var.;
%END;
%MEND;
%test;
ERROR: Required operator not found in expression: &var. in (1,2)
Upvotes: 1
Views: 1683
Reputation: 51621
If you want the macro processor to treat IN (or #) as an operator (and not the plain text it was for the first 25 years of SAS coding) you have to tell SAS to do that. As noted in the macro language manual table of operators: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1alyfc9f4qrten10sd5qz5e1w5q.htm
There are SYSTEM options to do that, MINOPERATOR and MINDELIMITER.
But for a macro the best way is on the %MACRO statement that is defining the macro. That way the macro works even if the caller of the macro has set the system options in some other way.
%macro test / minoperator mindelimiter=',';
%if &var. in (1,2) %then %do;
%put &=var is in (1,2);
%end;
%mend;
%let var = 1;
%test;
Result:
93 %let var = 1;
94 %test;
VAR=1 is in (1,2)
Upvotes: 1
Reputation: 31
In order to use the In operator in a macro function you have to use
options minoperator on;
before running your macro.
Sure would be helpful if SAS documented that anywhere or the error told you this was what you needed. We spent half a day trying to debug code where this was the issue.
Upvotes: 0
Reputation: 44
Use of "In" in the %IF needs to be changed to the below code. or use %index function
%GLOBAL var;
%LET var = 1;
%MACRO test;
%IF **&var.=1 or &var.=2** %THEN %DO;
%PUT &var.;
%END;
%if %index
%MEND test;
%test;
Upvotes: 1