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?
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: */
> input pid text $ 3-43;
>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;
>/* 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(~));
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
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
"%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:
%let x2 = %bquote(%abc ¯o1 % %uvw ¯o2);
The answer is 8. Lei explains it like so:
"Since < %abc ¯o1 % %uvw ¯o2 > 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 ¯o1 % %uvw ¯o2 >, a text
"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."