Reputation: 293
Has anyone encountered the below error:
options symbolgen mprint mlogic minoperator;
%macro test /minoperator mindelimiter=',';
%let var1 = EXPORT;
%if &var1 in (EXPORT, TEST,TEST1) %then %let var_final1=1;
%put &=var_final1.;
%let var_final2 = %sysfunc(ifc(&var1= EXPORT,1,2));
%put &=var_final2;
%let var_final3 = %sysfunc(ifc(&var1 in (EXPORT, TEST,TEST1),1,2));
%put &var_final3;
%mend;
%test;
var_final1 and var_final2 are working okay, whereas, for var_final3 where we have ifc function, i get the below error:
ERROR: Argument 1 to function IFC referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC
or %QSYSFUNC function reference is terminated.
Not sure why the IN operator does not work with IFC or IFN functions?
Can anyone please suggest.
Thanks
Upvotes: 0
Views: 265
Reputation: 51611
It is a very tricky job %SYSFUNC() has been given. It has to figure out how to convert your macro text into variables/expressions it can pass to the function it is trying to call. In this case it cannot figure out the IN
operator. Perhaps it doesn't know about the MINOPERATOR option.
You can fix it by making its problem easier by adding an explicit call to %EVAL()
so that all that it needs to pass to the IFN() function is the resulting zero or one.
%let var_final3 = %sysfunc(ifc(%eval(&var1 in (EXPORT, TEST,TEST1)),1,2));
Upvotes: 1
Reputation: 61
I think you just need to evaluate your 'in' expression so that the ifn or ifc function sees it as a boolean value:
options symbolgen mprint mlogic minoperator;
%macro test /minoperator mindelimiter=',';
%let var1 = EXPORT;
%if &var1 in (EXPORT, TEST,TEST1) %then %let var_final1=1;
%put &=var_final1.;
%let var_final2 = %sysfunc(ifc(&var1= EXPORT,1,2));
%put &=var_final2;
%let var_final3 = %sysfunc(ifc(%eval(&var1 in (EXPORT, TEST,TEST1)),1,2));
%put &var_final3;
%mend;
%test;
Upvotes: 0