BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Syntas_error
Quartz | Level 8

I know that same named variables can be present in both the global and local symbol tables with different values,  but can same named macro variables be present in two or more local symbol tables concurrently, having different values? 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Absolutely.  Here's a test:

 

%macro a (var=5);

   %put _user_;

%mend;

 

%macro b (var=10);

   %a

%mend b;

 

%b ()

 

View solution in original post

2 REPLIES 2
Astounding
PROC Star

Absolutely.  Here's a test:

 

%macro a (var=5);

   %put _user_;

%mend;

 

%macro b (var=10);

   %a

%mend b;

 

%b ()

 

Tom
Super User Tom
Super User

Absolutely.

When running SAS will return the result from the "inner most" scope.  Think of macro scope like nesting dolls.

 

If the macro variable MVAR1 exist as GLOBAL (or some outer scope) but your macro (or some intervening macro scope) also has a local macro variable named MVAR1 then that outer version is hidden. 

 

If you really need know what the value in that outer scope is you could use this utility macro.

https://github.com/sasutils/macros/blob/master/symget.sas

RawCode

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1011 views
  • 4 likes
  • 3 in conversation