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 (January 2012, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 28 Jan 2012 11:30:10 -0500
Reply-To:     bbser 2009 <bbser2009@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         bbser 2009 <bbser2009@GMAIL.COM>
Subject:      Re: Two short marcos, one works, one not
Comments: To: Quentin McMullen <qmcmullen.sas@gmail.com>
In-Reply-To:  <CACsQYve8yR33mYdkLUav=CTZ8yJSpbMkoY3H5_umRoW6Vz=EKQ@mail.gmail.com>
Content-Type: text/plain; charset="us-ascii"

Quentin (and all):

Thank you for your comments. I made those examples for the purpose of understanding the code I mentioned in another thread on SAS-L. Anyway, here is another code in that regard, which only use %bquote and it works fine!

*This code works!; %macro zzzz; %if %bquote(')=%bquote(') %then %put ok; %else %put not ok; %mend zzzz;

%zzzz

This seems even weirder when comparing this code with the following non-working code I mentioned previously:

*This code does NOT work!; %macro xxxx; %if %bquote(%str(%'))=%bquote(') %then %put ok; %else %put not ok; %mend xxxx;

%xxxx

I hope I am not torturing you and others who are thinking about this thread. ;)

Regards, Max (Maaxx)

-----Original Message----- From: qmcmullen@gmail.com [mailto:qmcmullen@gmail.com] On Behalf Of Quentin McMullen Sent: January-28-12 10:12 AM To: SAS-L@LISTSERV.UGA.EDU; bbser 2009 Subject: Re: [SAS-L] Two short marcos, one works, one not

Hi Max,

Well I was disappointed to see this example. I don't have an answer, but I do have some comments.

I simplified your code a bit, with the same disappointing finding as inspired your question:

%macro xxxx; %if %bquote(')=%str(%') %then %put ok; %else %put not ok; %mend xxxx; %xxxx

%macro yyyy; %if %str(%')=%bquote(') %then %put ok; %else %put not ok; %mend yyyy; %yyyy

To me, the question is why does the first example work? That is, since %bquote is an execution time quoting function, I expect both versions of the macro to choke during macro compilation due to unmatched quotes.

I turned on mlogic, and it showed I think some things of interest:

Note that below there are no boxes indicating that the quote marks are masked.

152 %macro xxxx; 153 %if %bquote(')=%str(%') 154 %then %put ok; 155 %else %put not ok; 156 %mend xxxx; 157 %xxxx MLOGIC(XXXX): Beginning execution. MLOGIC(XXXX): %IF condition %bquote(')=%str(%') is TRUE MLOGIC(XXXX): %PUT ok ok MLOGIC(XXXX): Ending execution.

If you remove %bquote from the left side, mprint shows you that %str() has masked its quote, as expected:

158 %macro nobquote; 159 %if house=%str(%') 160 %then %put ok; 161 %else %put not ok; 162 %mend; 163 %nobquote MLOGIC(NOBQUOTE): Beginning execution. MLOGIC(NOBQUOTE): %IF condition house= is FALSE MLOGIC(NOBQUOTE): %PUT not ok not ok MLOGIC(NOBQUOTE): Ending execution.

Simply adding an (unneeded) %bquote to the left side does not change this.

164 %macro bquotenoquote; 165 %if %bquote(house)=%str(%') 166 %then %put ok; 167 %else %put not ok; 168 %mend; 169 %bquotenoquote MLOGIC(BQUOTENOQUOTE): Beginning execution. MLOGIC(BQUOTENOQUOTE): %IF condition %bquote(house)= is FALSE MLOGIC(BQUOTENOQUOTE): %PUT not ok not ok MLOGIC(BQUOTENOQUOTE): Ending execution.

But if you add an unmatched quote inside the %bquote, then (according to mlogic at least), %str() is no longer hiding its unmatched quote, which seems odd indeed.

178 %macro bquotewithquote; 179 %if %bquote(ho'use)=%str(%') 180 %then %put ok; 181 %else %put not ok; 182 %mend; 183 %bquotewithquote MLOGIC(BQUOTEWITHQUOTE): Beginning execution. MLOGIC(BQUOTEWITHQUOTE): %IF condition %bquote(ho'use)=%str(%') is FALSE MLOGIC(BQUOTEWITHQUOTE): %PUT not ok not ok MLOGIC(BQUOTEWITHQUOTE): Ending execution.

And if you have %bquote() on the left with an unmatched quote, and no unmatched quote on the right, then the macro will not compile, due to the unmantched quote (as expected).

%macro bqouteNOstr; %if %bquote(ho'use)=house %then %put ok; %else %put not ok; %mend;

Other than those observations, I'm still at a loss to explain why %bquote is behaving this way. It doesn't match wth my expectations/understanding. Look forward to hearing from others.

Kind Regards, --Quentin

On Sat, Jan 28, 2012 at 12:20 AM, bbser 2009 <bbser2009@gmail.com> wrote: > Greetings all! > > I have two short macros as shown below. > The second code is obtained by merely swapping the left-hand and right-hand > sides of the logical equality in the first code. > But the first works fine, the second does not work. > Could you please explain the reason? Thank you very much in advance! > > Best regards, Max > (Maaxx) > > *This code works.; > %macro xxxx; > %if %bquote(')=%bquote(%str(%')) > %then %put ok; > %else %put not ok; > %mend xxxx; > > %xxxx > > > *This code does NOT work!; > %macro xxxx; > %if %bquote(%str(%'))=%bquote(') > %then %put ok; > %else %put not ok; > %mend xxxx; > > %xxxx


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