When Local Variables in Different Routines Have the Same Name
The concept of variable scope can be confusing when local variables in different routines
have the same name. When this occurs, each local variable is distinct. In the following
example, the DATA step and CALL routines subA and subB contain a local variable
named x. Each x is distinct from the other x variables. When the program executes, the
DATA step calls subA and subA calls subB. Each environment writes the value of x to
the log. The log output shows how each x is distinct from the others.
proc fcmp outlib=sasuser.funcs.math;
subroutine subA();
x=5;
call subB();
put 'In subA: ' ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.