DATA Step, Macro, Functions and more

difference between %nrbquote and %superq

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

difference between %nrbquote and %superq

Hello Forum,

I have following code that uses %nrbquote and %superq to give the same results. I was curious what is the difference between them. Can I use %nrbquote in place of %superq and vice vera?  Thanks for any insights.

%let a=%nrstr(Kaushal&Alex);

     %let c=%nrquote(&a);

%put &c;

%let a=%nrstr(Kaushal&Alex);

   %let c=%superq(a);

%put &c;


Accepted Solutions
Solution
‎11-12-2014 12:22 PM
Super User
Posts: 5,079

Re: difference between %nrbquote and %superq

Kaushal,

In Loko's code, there was a live (unquoted) & captured by CALL SYMPUT.

In your code, the & is quoted by %nrstr.  All the subsequent quoting functions maintain the quoted status of the &, thus there is no resolution of &Alex.

To illustrate, also try:

%put %unquote(&c);

It's always a good thing to run tests when using quoting functions in macro language!

Good luck.

View solution in original post


All Replies
Super User
Super User
Posts: 7,392

Re: difference between %nrbquote and %superq

Super Contributor
Posts: 305

Re: difference between %nrbquote and %superq

Hello,

I have also tried to figure out differences between the 2 functions and I could hardly find. There is one situation where I have found differences :

data _null_;
call symput('word', 'ben&jerry');
run;

%put &word;
%put %nrbquote(&word); -->ISSUES WARNING
%put %superq(word);-->DOES NOT ISSUE WARNING

Super User
Posts: 5,079

Re: difference between %nrbquote and %superq

Loko,

%nrbquote will continue to resolve macro variable references.  To see the difference (and perhaps shed some light on why you get a warning), try adding this statement before you run your code:

%let jerry=jamin;

Contributor
Posts: 50

Re: difference between %nrbquote and %superq

Hello Astounding,

In this code, I am not sure why macro variable Alex is not resolved in %nrbquote?  As you mentioned "%nrbquote will continue to resolve macro variable references".

%let Alex=Jamin;

%let a=%nrstr(Kaushal&Alex);

%let c=%nrquote(&a);

%put &c;

Solution
‎11-12-2014 12:22 PM
Super User
Posts: 5,079

Re: difference between %nrbquote and %superq

Kaushal,

In Loko's code, there was a live (unquoted) & captured by CALL SYMPUT.

In your code, the & is quoted by %nrstr.  All the subsequent quoting functions maintain the quoted status of the &, thus there is no resolution of &Alex.

To illustrate, also try:

%put %unquote(&c);

It's always a good thing to run tests when using quoting functions in macro language!

Good luck.

Contributor
Posts: 50

Re: difference between %nrbquote and %superq

Great !!! Thanks a bunch, Astounding.

New Contributor
Posts: 2

Re: difference between %nrbquote and %superq

SUPERQ masks the same characters as the %NRBQUOTE function. However, %SUPERQ does not attempt to resolve anything in the value of a macro variable. %NRBQUOTE attempts to resolve any macro references or macro variable values in the argument before masking the result.

SUPERQ is the only quoting function that prevents the resolution of macro variables and macro references in the value */
of the specified macro variable.*/

SUPERQ accepts only the name of a macro variable as its argument, without an ampersand, and the other quoting functions accept any text expression, including constant text, as an argument.*/

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 925 views
  • 7 likes
  • 5 in conversation