DATA Step, Macro, Functions and more

MOD in macro error

Accepted Solution Solved
Reply
Super Contributor
Posts: 503
Accepted Solution

MOD in macro error

Hi Everyone,

 

I run a macro and would like to do proc copy whenever the count is even number.

I received error notice and am not sure how to fix it.

 

NOTE: %INCLUDE (level 1) ending.
ERROR: Required operator not found in expression: MOD(&GROUP,2)=0
ERROR: The macro OUTER_LOOP will stop executing.

 

Any help is very appreciated.

HHCFX

%MACRO OUTER_LOOP;
%DO GROUP=1 %TO &MAX_GROUP;
... Mycode
%include "C:\mysas_code.sas" /lrecl=500;
*export subsample of final file; %if MOD(&GROUP,2)=0 %then %do; data F2_&group; set F2; run; proc copy in=work out=myfolder; select F2_&group;run; %end; %END; %MEND; %OUTER_LOOP; run;

Accepted Solutions
Solution
‎03-27-2018 06:53 PM
PROC Star
Posts: 1,356

Re: MOD in macro error

a quick look tells me you need %sysfunc to invoke sas functions

like

%MACRO OUTER_LOOP;
%DO GROUP=1 %TO &MAX_GROUP;
... Mycode
 %include "C:\mysas_code.sas" /lrecl=500;
	*export subsample of final file;
	%if %sysfunc(MOD(&GROUP,2)=0 )%then %do;
	data F2_&group; set F2; run;
	proc copy in=work out=myfolder; select F2_&group;run;
	%end;
%END;

%MEND;

%OUTER_LOOP; run;

 

View solution in original post


All Replies
Solution
‎03-27-2018 06:53 PM
PROC Star
Posts: 1,356

Re: MOD in macro error

a quick look tells me you need %sysfunc to invoke sas functions

like

%MACRO OUTER_LOOP;
%DO GROUP=1 %TO &MAX_GROUP;
... Mycode
 %include "C:\mysas_code.sas" /lrecl=500;
	*export subsample of final file;
	%if %sysfunc(MOD(&GROUP,2)=0 )%then %do;
	data F2_&group; set F2; run;
	proc copy in=work out=myfolder; select F2_&group;run;
	%end;
%END;

%MEND;

%OUTER_LOOP; run;

 

Super User
Posts: 6,543

Re: MOD in macro error

Alternatively, you could take advantage of this combination.  %IF always applies %EVAL, and %EVAL performs integer arithmetic.  So you could code:

 

%if &group = &group / 2 * 2 %then %do;

Super Contributor
Posts: 503

Re: MOD in macro error

Posted in reply to Astounding

Thanks a lot!

It works perfectly.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 110 views
  • 3 likes
  • 3 in conversation