Date: Sat, 21 Aug 2010 16:34:49 -0400
Reply-To: Tom Abernathy <tom.abernathy@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Tom Abernathy <tom.abernathy@GMAIL.COM>
Subject: Re: Chance to Make SAS-L History: Did You Know That...
External macro variables.
External macro variables are any macro variables currently in the macro
symbol table that are not local to the currently executing macro. Some
programs use the %GLOBAL statement in order to return values from an
executing macro to the calling environment. But SAS will generate an error
if you attempt to define as GLOBAL a macro variable that is already defined
as local. Any external macro variable can be modified and it so will be
returned to the caller. Instead of using %GLOBAL statements you just need to
define the variable before invoking the nested macro.
SAS does not have functions to help programs determine if a macro variable
is external or not. The functions it does have can be used to test if a
macro variable exists (%SYMEXIST) and whether it is global (%SYMGLOBL) or
not (%SYMLOCAL). But the %SYMLOCAL function does NOT tell you if the macro
variable is in the current scope, just that it exists and is not global.
You can get the list of external macro variables by querying the SAS
metadata table DICTIONARY.MACRO (or the view SASHELP.VMACRO) and excluding
those with scope of the currently running macro.
Example:
proc sql noprint;
select distinct name into :external separated by ' '
from dictionary.macros
where scope not in ("&sysmacroname","AUTOMATIC")
;
quit;