BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
DMGNole
Calcite | Level 5

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;
1 ACCEPTED SOLUTION

Accepted Solutions
SASJedi
SAS Super FREQ

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;

 

 

Check out my Jedi SAS Tricks for SAS Users

View solution in original post

6 REPLIES 6
SASJedi
SAS Super FREQ

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;

 

 

Check out my Jedi SAS Tricks for SAS Users
DMGNole
Calcite | Level 5

This worked. Thank you very much! It is good practice to use the %symputx and %qsysfunc. I will make sure I start doing that.

Tom
Super User Tom
Super User

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.

SASJedi
SAS Super FREQ

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...  

Check out my Jedi SAS Tricks for SAS Users
ballardw
Super User

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?

DMGNole
Calcite | Level 5

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1244 views
  • 1 like
  • 4 in conversation