BookmarkSubscribeRSS Feed

It would be very convient to be able to specify a %GLOBAL macro variable and an initial value with a single statement similar to how you can establish a READONLY variable but have it updateable.

%GLOBAL variable=ABC;

rather than haveing to code...

%GLOBAL variable;

%LET variable=ABC;

Super User

%Global and %local set status. Don't confuse it by overloading it with trying to parse some of the nonsense some people try when assigning values.



Consider a "value" that has a space in it such as :

%global somevar=this is problematic assignment;

Is the "is" above after the space a new macro variable that is having the status set or part of the value? What would the parsing rules be? Remember the existing rules for %global and %local allow setting the status on a list of space delimited variables, not to mention that the list might itself be a macro variable.

Using quotes or other "special" character to delimit start and end of the value would cause a significant difference from how %let assigns macro values and would likely not make anyone's code more robust in the long run.


I can just see the fun trying to trace down the problems someone could create with

%global &somevar. = &someothervar.;

If you think this is desirable then write your own utility macro to do such with a %global and %let statement. Pretty trivial to create something that could be called as %myglobal(varname, value);

Obsidian | Level 7

Seems like a pretty straight forward suggestion.  If you find it confusing then don't use it.  SAS provides many ways to do the same thing.  As a product developer supporting SAS applications for many years I would find this helpful.  It does not seem confusing when I create a READONLY GLOBAL variable.


If you're in "open" code (i.e. outside of a macro), then you don't need the %GLOBAL statement.  You can just use the %LET statement and it will create a global macro variable.


So seems like this would only be useful in the (rare) instance where you are inside a macro and want to create a global macro variable and assign it a value.  


Is that right?


Personally, since I try to avoid global macro variables, this wouldn't help me much.  I was excited for /ReadOnly global macro variables, because I think if you are going to use global macro variables, making them read only so that their value is constant for the SAS session is a really good idea.  But in testing, I realized that if you have a GLOBAL macro var FOO, SAS will throw an error if you try to create a local macro variable FOO.  I find that horrifying, and as a result avoid using /readonly.

Opal | Level 21

The proposed syntax looks problematic to me. Consider this:

%global VarList=Var1 Var2;

This can be interpreted as a single global macro variable Varlist with the value "Var1 Var2" or two global macro variables, Varlist with a value of Var1 and Var2 without an initial value. There would need to be a boundary indicator between macro variables to avoid confusion.


Personally I think this is overly complicating the %GLOBAL statement. I'd be interested to know what others think.  

Obsidian | Level 7

SAS already supports specifying the value of a /READONLY GLOBAL variable in a single statement.  Maybe if you review the doc on how this works it would be clearer to you.