%macro xyz;
%do i=1 %to 20 ;
if mod(%eval(&i,2))=0 %then %do;
%end;
%end;
%mend;
%xyz;
error
Do what?
Your "if" is wrong to execute in macro processing, it should be %if.
To call data step functions you have to use %sysfunc(function(parameters))
%macro xyz; %do i=1 %to 20 ; %if %sysfunc (mod(&i,2))=0 %then %do; %end; %end; %mend;
%macro xyz;
%do i=1 %to 20 ;
data even;
%if %sysfunc (mod(&i,2))=0 %then %do;
%end;
run;
%end;
%mend;
%xyz;
@BrahmanandaRao wrote:
%macro xyz; %do i=1 %to 20 ; data even; %if %sysfunc (mod(&i,2))=0 %then %do; %end; run; %end; %mend; %xyz;
NOW you really need to describe everything that you are actually attempting to do. %if code does not recognize the values of data step variables. Macro statements inside data step must generate valid data step (or other procedure) code. Since the code you show does not generate data step code it does nothing except create a data set named even, with no variables and gets overwritten 19 times after initial creation.
At this point I would say that one possible "solution" is : 42 .
As always, @BrahmanandaRao we need much more explanation from you. Your posts are consistently too brief, causing us to guess and often guess wrong and then we have to ask follow-up question after follow-up question. Explain. Provide details about what you are trying to do, in words, not SAS code, and explaining the background and reasons. Emphasis on details. Emphasis on background. Emphasis on explain. Don't make us constantly ask you for additional details and ask why you are doing this; provide all relevant details in the first post. We're trying to help you, but you have to help us.
Your code (once corrected to use %IF and %SYSFUNC) will do nothing, so it's not worth bothering with.
Rule #1 of macro development: start with working, non macro code. So please show the code you want to make dynamic, and describe what needs to be repeated, and how.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.