Hello!
for a project I need to make macro invocations at different levels in do loops (see next example) so inside a master macro I have to loop over other ones and these macros that I invoke can do de same. My problem is that if I use the same index in the do loop in the master macro and the invoked macro (in this case "i") when the invoked macro is executed it modifies the index of the loop in the master macro, resulting in an unexpected result:
%macro macro1();
%do i = 1 %to 5;
%put first_level_macro: &i.;
%macro2;
%end;
%mend;
%macro macro2();
%do i = 1 %to 5;
%put second_level_macro: &i.;
%end;
%mend;
%macro1;
Result:
first_level_macro: 1
second_level_macro: 1
second_level_macro: 2
second_level_macro: 3
second_level_macro: 4
second_level_macro: 5
Desired result:
first_level_macro: 1
second_level_macro: 1
second_level_macro: 2
second_level_macro: 3
second_level_macro: 4
second_level_macro: 5
first_level_macro: 2
second_level_macro: 1
second_level_macro: 2
second_level_macro: 3
second_level_macro: 4
second_level_macro: 5
first_level_macro: 3
second_level_macro: 1
second_level_macro: 2
second_level_macro: 3
second_level_macro: 4
second_level_macro: 5
first_level_macro: 4
second_level_macro: 1
second_level_macro: 2
second_level_macro: 3
second_level_macro: 4
second_level_macro: 5
first_level_macro: 5
second_level_macro: 1
second_level_macro: 2
second_level_macro: 3
second_level_macro: 4
second_level_macro: 5
I know that I can simply change the name of the index in the master macro, but given the requirements of my project this is not possible, because we are integrating a lot of macros at several levels and we can not change the indexes names on each one of them.
Is there a way to solve this without changing the names of the indexes?
Thank you,