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 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 6 Jan 2005 13:52:52 -0500
Reply-To:     "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
Subject:      Re: Quoting issue: when and why does quoting function NR... try
              to resolve something?
Comments: To: dubro@DOLIC.DE

On Thu, 6 Jan 2005 09:58:41 -0800, Dubravko Dolic <dubro@DOLIC.DE> wrote:

>Hi all maco mavens out there. > >Could any one be so kind and have a look on the following example: > >/* Example data: */ >data text; > input pid text $ 3-43; >datalines; >1 "Patient feels ill" >2 20% loss of phrems. >3 broken leg, not treated >4 very ser. illness &deliv. into hosp. >; > >/* Write content of variable TEXT into a macro variable TEXT */ >proc sql noprint; > select text into :text separated by "~" from text; >quit; > >/* This leads to errors and warnings */ >%put %scan(&text, 1, %str(~)); >/* This too */ >%put %scan(%str(&text), 1, %str(~)); >/* quotes only at compilation time, so no question... */ >%put %scan(%nrstr(&text), 1, %str(~)); >/* ... */ >%put %scan(%bquote(&text), 1, %str(~)); >/* > Why does NRBQUOTE not protect the macro processor from > resolving &DELIV? >*/ >%put %scan(%nrbquote(&text), 1, %str(~)); *<--- HERE IS MY QUESTION; >/* This works */ >%put %scan(%superq(text), 1, %str(~)); > Hi, Dubro,

That is why we need a separate %superq() function, I guess. The %nrbquote () will resolve the macro text expression as far as possible and mask the result.

One thing a bit confusing is the difference between %nrbquote and %bquote and the best explanation I've got was from Lei Zhang, he wrote to me (privately):

"%Bquote and %NRBquote will instruct the SAS macro processor to resolve (macro) text expression as far as possible and mask the result. For %NRBquote, it turns the result into a text constant, which is not for rescaning in the future.

"For %BQuote, if the result don't include % and &, the masked result is a text constant; if the result contain & and %, the masked result is still a text expression because % and & haven't been masked, and they are meaningful to macro processor."

See if you really understand by guessing how many warnning messages the following macro would generate:

%macro lei; %let x2 = %bquote(%abc &macro1 % %uvw &macro2); %mend; %lei

The answer is 8. Lei explains it like so:

"Since < %abc &macro1 % %uvw &macro2 > is a text expression, it causes macro processor to resolv it. Because macro processor cannot resolve it at all during the execution period, it will generate first 4 warning messages. The return string from resoltion is still < %abc &macro1 % %uvw &macro2 >, a text expression.

"Then, %Bquote try to mask the result, or rescan the result for masking. When it see % and & in the returned string, %Bquote will try to have macro processor to resolve it again. That is why you have the other 4 warning messages."

HTH.

Cheers, Chang


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