LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 22 Aug 2007 09:28:03 -0700
Reply-To:   "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Subject:   Re: nested macros and leading spaces
Comments:   To: Joey Morris <rjmorris12@YAHOO.COM>
In-Reply-To:   <200708221538.l7MFRkEW015787@mailgw.cc.uga.edu>
Content-Type:   text/plain; charset="us-ascii"

Hi Joey,

Hey, interesting. If you were to turn on OPTION SYMBOLGEN; you can see that for the original discussion, as seen in both outputs of spaces2:

%put [%spaces2];

%let rc = %spaces2; %put [&rc.];

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 expected result.

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; different?

%put hello; %put hello;

%let xx=hello; %put &xx; %let xx= hello; %put &xx;

%macro yy; hello %mend; %macro yyy;

hello %mend;

%macro yyyy; %nothing hello %mend; %macro yyyyy; %nothing

hello %mend; %put %yy; %put %yyy; %put %yyyy; %put %yyyyy; %put [%yy]; %put [%yyy]; %put [%yyyy]; %put [%yyyyy];

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.

Mark

-----Original Message----- 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 <Mterjeson@RUSSELL.COM> wrote:

>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(); >or > %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 ---

%macro nothing1; %mend;

* The first line of spaces1 contains 4 blanks. ; %macro spaces1;

111 %mend;

%macro spaces2; %nothing1 222 %mend;

%put [%spaces1]; %put [%spaces2];

--- Log ---

[111] [ 222]

Also, I get the same behavior when the inner call does have arguments:

%macro nothing2(arg); %mend;

%macro spaces3; %nothing2(dummy) 333 %mend;

%put [%spaces3];

--- Log --- [ 333]

So I don't think it's simply the parens causing the problem.

>-----Original Message----- >From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of >Joey >Sent: Tuesday, August 14, 2007 11:51 AM >To: SAS-L@LISTSERV.UGA.EDU >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 >not. > >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. >Joey > > >--- Code --- > >%macro nothing(); >%mend; > >* The first line of spaces1 contains 4 blanks. ; >%macro spaces1(); > > 111 >%mend; > >%macro spaces2(); > %nothing() > 222 >%mend; > >%macro spaces3(); > %local dummy; > %let dummy = %nothing(); > 333 >%mend; > >%put [%spaces1()]; >%put [%spaces2()]; >%put [%spaces3()]; > >%let rc = %spaces2(); >%put [&rc.]; > >-- Log --- > >[111] >[ 222] >[333] >[222]


Back to: Top of message | Previous page | Main SAS-L page