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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 601 views
  • 4 likes
  • 3 in conversation