I'm testing this quarter end logic to run some code and keep getting this error:
ERROR: Required operator not found in expression: %sysfunc(month(&me)) in (3,6,9,12)
ERROR: The macro QRUN will stop executing.
data null;
set oddother.inputs;
call symput('me', monthend);
run;
%macro qrun;
%if %sysfunc(month(&me)) in (3,6,9,12) %then
%put success!;
%mend qrun;
%qrun;
You can't use the IN operator in a macro definition without the /MINOPERATOR option on the %MACRO statement. Also, the macro IN operator only supports space-delimited lists - no commas allowed. Finally, as an aside, you should use SYMPUTX in your DATA step to make sure the value stored does not include leading or trailing blanks. Try this:
data null;
set oddother.inputs;
call symputx('me', monthend);
run;
%macro qrun/minoperator;
%if %qsysfunc(month(%superq(me))) in (3 6 9 12) %then
%put NOTE: success!;
%else
%put NOTE: Month of &me is %qsysfunc(month(&me)) ;
%mend qrun;
%qrun;
You can't use the IN operator in a macro definition without the /MINOPERATOR option on the %MACRO statement. Also, the macro IN operator only supports space-delimited lists - no commas allowed. Finally, as an aside, you should use SYMPUTX in your DATA step to make sure the value stored does not include leading or trailing blanks. Try this:
data null;
set oddother.inputs;
call symputx('me', monthend);
run;
%macro qrun/minoperator;
%if %qsysfunc(month(%superq(me))) in (3 6 9 12) %then
%put NOTE: success!;
%else
%put NOTE: Month of &me is %qsysfunc(month(&me)) ;
%mend qrun;
%qrun;
This worked. Thank you very much! It is good practice to use the %symputx and %qsysfunc. I will make sure I start doing that.
Why would you add macro quoting to the result of the MONTH() function?
The only possible values are integers from 1 to 12 and missing value.
None of those need macro quoting.
This is a matter of style, much like when some coders follow every macro reference with a '.' whether it needs delimiting or not. When I write macro code, if the text resulting from a macro expression is not intended to trigger additional macro processing (i.i, is text to be generated and not macro code) I always quote the results. This works, and the habit has saved me hours of troubleshooting while tracking down underquoted text generated during execution. You could certainly use an unquoted macro reference here if desired. I just like to establish coding habits that generally work in all situations and go with that...
How many records in oddother.inputs?
Which value of Monthend are you expecting? The shown code will use the last value of the variable in the data set.
What if Monthend is missing for the last observation?
Are you sure that the Monthend variable is a SAS date?
This is our main lookup table for all of our processing which contains important date values among other things. It is just one row with this info. This is solved now. Thank you for the quick response!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.