The answer to WHY the domain definition rules were defined for this without knowing the history of macro language.
When I learned macro language (6.12), I was fortunate enough to learn from an early age that macros should always declare their% LOCAL variables, unless they had a really good reason. Sometimes, if the var macro was not declared as% local or% global, I would even put a comment /* Not Local: MyMacVar */ to document that I was not going to declare a region (this is unusual, but sometimes useful). It pains me to see UG docs, SO responses, etc. that donโt declare variables like% LOCAL.
I'm going to guess (it's just a hunch) that there was an early version of SAS that had (global) macro variables to generate text in code, but didn't have macros. Thus, in this version, people would be accustomed to having many global macro variables and related problems (for example, collisions). Then, when SAS designed the macros, the question would be: โCan I reference my macro vars from a macro?โ And the designer decided to answer โyes, you can not only refer to them, but assign values โโto them, and I will do this easily by allowing you to do this by default. But also the macro will create its own region that can contain local macro variables. If you refer to the var macro, or assign a var macro with the same name as the var macro that exists in the global scope (or any outer scope), I assume that you are referencing the global macro as a variable (as you are used to), unless you explicitly declared the macro var as% LOCAL. "
From the perspective of a modern macro language / macro developer, most people think that most global macros should be avoided. And one of the advantages of a macro language is that it provides macros that allow modulation / encapsulation / hiding of information. Seen from this point of view,% local variables are more likely, and macro variables that are not declared as% local are dangerous for encapsulation (i.e. collision threats). Therefore, I would agree that if I redesigned the macro language, I would have made the% local default macro variables. But of course, at this point, it is too late for a change.
source share