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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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