|
On Mar 23, 7:39 am, RolandRB <rolandbe...@hotmail.com> wrote:
> On Mar 23, 6:54 am, RolandRB <rolandbe...@hotmail.com> wrote:
>
>
>
>
>
> > I hit this problem last night after several hours of coding and
> > thought I was hallucinating. Correct me if I'm wrong but is it not the
> > case that when you do a "call symput" from inside a macro then the
> > scope should be limited such that it is local to that macro? That *is*
> > what the documentation says, n'est pas? Then how come MACROVAR is
> > global when I ran my code?
>
> > 9 %macro mymacro;
> > 10 data _null_;
> > 11 call symput('macrovar',"ABCDE");
> > 12 run;
> > 13 %mend mymacro;
> > 14 %mymacro
>
> > NOTE: DATA statement used (Total process time):
> > real time 0.00 seconds
> > cpu time 0.00 seconds
>
> > 15
> > 16 %put _global_;
> > GLOBAL MACROVAR ABCDE
>
> I've got it. The coffee has worked. You need to specify at least ONE
> parameter with the macro, even if it is a dummy parameter that you
> don't even refer to, to get the "call symput"s to create LOCAL macro
> variables. With no macro parameters, the "call symput"s will be
> GLOBAL.- Hide quoted text -
>
> - Show quoted text -
Actually, thinking about it a bit more, I do find this odd. I was in a
situation where, for the first time in my SAS coding career, I decided
to use a dataset to supply macro parameters and their values rather
than use macro parameters. So I had a macro with no parameters that
instead was designed to pick up all the parameters and their values
from a dataset (actually two datasets). I was expecting a "call
symput" within that macro to symput to local macro variables, as has
worked for me for many years, and instead I found them to be set up as
global macro variables. Just the inclusion of a dummy positional macro
parameter in the macro declaration, that never gets referred to in the
macro code, changed the "call symput" action to LOCAL, rather than
GLOBAL. I find that arbitrary and somewhat odd. At least I know now. I
had read the official sas documentation on this and found it unclear
where they talked about the "most local nonempty symbol table". I
tried setting a dummy local macro variable within the macro, before
the "call symput"s, in the hope that it would clear the problem but
that did not work. It has to be a macro parameter declared with the
macro definition. This was not clear in the documentation.
Anyhow, job done, but it lost me many hours of productive work. I was
working to a tight schedule and eight hours are now lost out of it. I
would like to thank the SAS Institute for the many hundreds of hours
of stress, mental agony and grief caused by their crappy documentation
that, so often, wins their internal documentation awards for
excellence. May you once have to program using your own code for a
day!
|