To refactor a program, I took a complex process I want to abstract and placed it within a macro.
%macro BlackBox();
data _null_;
put "This represents a complex process I want to abstract.";
run;
%mend;
The process needs to occur multiple times in succession, so the obvious solution is to place it within a loop.
data _null_;
do i = 1 to 3;
%BlackBox();
end;
run;
This, however, produces the following error.
ERROR 117-185: There was 1 unclosed DO block.
What is happening?
My best guess is that SAS is trying to run a data step within a data step.
I find that I can avoid this error by enclosing my loop within a macro and then immediately calling the macro.
%macro PerformDoLoop();
%do i = 1 %to 3;
%BlackBox();
%end;
%mend;
%PerformDoLoop;
All this seems like an roundabout way of handling a fundamental programming task. I'm hoping that learning more about why the data step approach fails will give me insight into how to complete this task more elegantly.
Please understand that this is a simplified example used to illustrate the error I am encountering. A real instance of the macro may take in arguments or return values.