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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 649 views
  • 4 likes
  • 3 in conversation