Date: Mon, 29 Jun 2009 09:57:45 -0400
Reply-To: Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject: Re: A better more flexible macro interface - response
On Sun, 28 Jun 2009 23:28:37 -0700, xlr82sas <xlr82sas@AOL.COM> wrote:
...
> Show me some code that returns a variable number of macro variables
>from the child to the parent macro,
> without creating dozens of global macro variables and without the
>parent macro knowing the number and names of all the macro variables.
...
Hi,
Stata's macro language has the c_local command (undocumented) that creates a
local macro variable in the parent's(i.e., caller's) scope. See http://tinyurl.com/kp5wpb or
http://www.stata.com/statalist/archive/2003-12/msg00391.html
It is obvious from the exchange on statalist that even the Nick Cox (who is
like Ian for sas, only more powerful as an editor of the Stata Journal) did
not know about c_local, nor understood why such command was necessary. Only
the founder and the main architect of stata (Bill Gould) could answer what
the c_local was good for succinctly (as of 2003). Wouldn't it be nice if Jim
Goodnight joins sas-l time to time and answers some of the deepest questions
about sas?
OK. on to the challenge. A nice solution has already been posted to sas-l
before. The idea is to return the quoted %local and %let statements that
creates macro variables when %unquoted in the parent macro. A stylish
implementation is done in the macro array context by Richard, freely
available at http://tinyurl.com/nqerl7 or http://devenezia.com/downloads/sas/macros/index.php?m=split
See how the SCOPE parameter works. HTH.
Cheers,
Chang
|