Hey, interesting. If you were to turn on
OPTION SYMBOLGEN; you can see that for the
original discussion, as seen in both outputs
%let rc = %spaces2;
that for the original discussion the extra
() paren characters were indeed the reason
for the 4 spaces.
Upon first investigation, removing all of the
() parens everywhere, the second %PUT of the
&rc. does trim down as expected.
Now that we have removed the () parens, the
&rc is resolving as expected. You now have
uncovered that for the %PUT of the %spaces2
there is now a different reason for the spaces.
[ and no you're definately not nuts. :o) ]
This is interesting...
You were on track for finding a dilemma, only
by removing the () parens do we truly have
"the unexpected". Having the parens was an
But now that we have removed the "easy" reason
for the spaces to be there, this new situation
turns out to be the same behavior for exactly
the same reason.
Now, without the parens you have a really good
question: why are %macro spaces1; and %macro spaces2;
%let xx= hello;
Yep, as seen with %put %yyyy the leading
spaces do get trimmed, and with your %nothing
present, especially with the leading non-space
square bracket, the presence of %nothing does
behave different than without. If you'll notice
that if you add extra line terminations (extra
blank lines) in both %macro yyy and yyyy, you
can deduce that (as seen on some occasions) the
SAS macro stuff sometimes generates a hidden
character to mark a placeholder for the macro
stuff to know where and what to do something.
If you'll notice adding additional blank lines
results in the hello text moving over to the
right one space for each line termination that
you add following the %nothing. Therefore,
your %nothing evidently resolves down to a
character when resolved and sent to the compiler
runtime which does not generate any code but the
presence of the special macro character influences
the %PUT statement in determining whether it ignores
the lineterminations and leading spaces or not.
So we have an idea of what is going on, but whether
or not the lack of ignoring lineterminations and
leading spaces following an enbedded macro fetch
operation that results in 'nothing' was an oversight
or not during initial development remains unknown.
From: Joey Morris [mailto:rjmorris12@YAHOO.COM]
Sent: Wednesday, August 22, 2007 8:38 AM
To: SAS-L@LISTSERV.UGA.EDU; Terjeson, Mark
Subject: Re: nested macros and leading spaces
On Tue, 14 Aug 2007 12:12:04 -0700, Terjeson, Mark
>When you do not have arguments being
>passed you do not need the () parens.
>SAS will ignore them on the %MACRO
>statement, but please note that they
>do NOT get used when you have no args.
>i.e. you can have
> %macro nothing();
> %macro nothing;
>these work the same, BUT, since you
>have no arguments, your call to %nothing
>does not use the trailing () parens.
Thanks for the reminder about not using parens when the call has no
arguments. I'll need to go back and read up on that.
>So, take all occurances of your () parens off
>everywhere (macro declarations and calls alike),
>and you'll see the text-substitution behavior
>that you desire.
Hmm...I've tried that and it doesn't help:
--- Code ---
* The first line of spaces1 contains 4 blanks. ;
--- Log ---
Also, I get the same behavior when the inner call does have arguments:
--- Log ---
So I don't think it's simply the parens causing the problem.
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>Sent: Tuesday, August 14, 2007 11:51 AM
>Subject: nested macros and leading spaces
>Does anyone know why the text produced by the second %put statement in
>the code below includes embedded spaces, but the first and third do
>not? I would have thought that %spaces1 and %spaces2 would be
>equivalent since the %nothing macro produces no text, but apparently
>I've been writing macros structured as in %spaces2 to call a nested
>macro and then to "return" a value, and my return values have leading
>spaces. Sometimes this is a problem and sometimes it isn't. I do know
>a few ways to work around this, such as using something like in
>%spaces3 or by assigning the return value from %spaces2() to another
>variable in a %let statement (since %let automatically trims leading
>and trailing spaces -- see %let rc =... below). But what I really want
>to know is why SAS is behaving this way in the first place.
>Thanks for any insights you may have.
>--- Code ---
>* The first line of spaces1 contains 4 blanks. ;
> %local dummy;
> %let dummy = %nothing();
>%let rc = %spaces2();
>-- Log ---