Interestingly, the two links you got, from @andreas_lds and @Kurt_Bremser do not really answer your questions. The first reference says very little about the scope of macro variables, the second actually contains a factual error:
A local symbol table can be created by any of the following:
the presence of one or more macro parameters
a %LOCAL statement
macro statements that define macro variables, such as %LET and the iterative %DO statement (if the variable does not already exist globally or a %GLOBAL statement is not used)
The statement marked in red is not correct. A local symbol table is created if a macro variable is defined that does not exist in the calling environment. But that does not necessarily mean a %GLOBAL variable, the variable could also be %LOCAL to a calling macro, e.g.:
%macro a;
%local i;
%do i=1 %to 5;
%b;
%end;
%mend;
%macro b;
%do i=1 %to 3;
%put Hello World;
%end;
%mend; %a;
This very silly example shows the danger of forgetting to declare your macro variables %LOCAL. If you submit this, it will keep writing "Hello World" in the log, until the log runs full or you press <ctrl-break>. Why? Because the I variable in %B is the same as the one in %A. So, there was no %GLOBAL I variable, yet no local symbol table in %B either.
Forgetting to declare macro variables %LOCAL is a very common mistake. Many years ago we even had to write SAS Institute and ask them to declare the variable I %LOCAL in one of their utility macros (I think it was %VERIFY).
... View more