Go Back   Rhinocerus > Newsgroup > Newsgroup comp.soft-sys.sas

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 03-23-2008, 10:08 AM
data _null_,
Guest
 
Posts: n/a
Default Re: Scope of macro variable using "call symput"

Too bad about all your lost productivity.

I think you could be help with SYMPUTX.

However, I don't understand why if your data, in this case the data to
drive your application, is stored in SAS data sets do you desire to
move it into macro variables. I would think that if the information
to drive the code generation is stored in a data set then you would
use a data step to gen the code. The data step is much easier to code
than macro language and you don't have that whole macro quoting issue
to deal with. I would say your "doing it all wrong".


CALL SYMPUTX(macro-variable, value <,symbol-table>);


Arguments


macro-variable
can be one of the following:

a character string that is a SAS name, enclosed in quotation marks.

the name of a character variable whose values are SAS names.

a character expression that produces a macro variable name. This form
is useful for creating a series of macro variables.

a character constant, variable, or expression. Leading and trailing
blanks are removed from the value of name, and the result is then used
as the name of the macro variable.
value
specifies a character or numeric constant, variable, or expression. If
value is numeric, SAS converts the value to a character string using
the BEST. format and does not issue a note to the SAS log. Leading and
trailing blanks are removed, and the resulting character string is
assigned to the macro variable.

symbol-table
specifies a character constant, variable, or expression. The value of
symbol-table is not case sensitive. The first non-blank character in
symbol-table specifies the symbol table in which to store the macro
variable. The following values are valid as the first non-blank
character in symbol-table:

G specifies that the macro variable is stored in the global symbol
table, even if the local symbol table exists.

L specifies that the macro variable is stored in the most local symbol
table that exists, which might be the global symbol table.

F specifies that if the macro variable exists in any symbol table,
CALL SYMPUTX uses the version in the most local symbol table in which
it exists. If the macro variable does not exist, CALL SYMPUTX stores
the variable in the most local symbol table.



On Sun, Mar 23, 2008 at 4:05 AM, RolandRB <rolandberry@hotmail.com> wrote:
>
> 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!
>

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Scope of macro variable using "call symput" Chang Chung Newsgroup comp.soft-sys.sas 0 03-24-2008 12:48 PM
SCL Joe (was RE: macro structure) Gregg P. Snell Newsgroup comp.soft-sys.sas 0 06-27-2006 07:59 PM
FW: Re: Adding Macro Variables Ian Whitlock Newsgroup comp.soft-sys.sas 0 02-09-2006 03:47 PM
Re: surveyselect question Zack, Matthew M. Newsgroup comp.soft-sys.sas 1 01-18-2005 06:26 PM
Re: macro variable contains invalid chars Fehd, Ronald J. Newsgroup comp.soft-sys.sas 1 10-25-2004 01:38 PM



All times are GMT. The time now is 12:57 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.