## compile time or execution time macro quoting function

Super Contributor
Posts: 285

# compile time or execution time macro quoting function

Hello,

When calling macro which macro quoting function should be used macro parameters?  In this example  both %nrstr and %nrbquote give the same result. Thanks !

``````
%macro m (par);
data a;
x = "&par";
run;
%mend m;
%m(%nrstr(A|B))

%macro m (par);
data b;
x = "&par";
run;
%mend m;
%m(%nrbquote(A|B))``````
Super User
Posts: 6,628

## Re: compile time or execution time macro quoting function

For this particular example, the answer is "none of the above".  This macro call should generate the same result:

%m(A|B)

So the first question should be whether macro quoting is necessary at all.  In this example, it isn't.  In general (in case your actual application is more complex than the one you have shown), the idea is that macro quoting removes special significance from characters that would impact the interpretation of the program.  Take the case where your macro defines a single parameter:

%macro m (varname);

Now this would be an illegal call to the macro since the comma is a significant character that identifies when one macro parameter ends and a new one begins:

%m (A, B)

To get "A, B" to be interpreted as the value of a single macro parameter:

%m (%str(A, B))

The %STR function removes the special significance of the comma, and treats it as text instead.  Suppose the situation were more complex:

%let list = A, B;

%m (&list)

Now the comma doesn't even appear in the macro call.  However, resolving &LIST generates a comma which causes the same problem as before.  That's when you need a macro function that quotes later on, as the macro executes:

%m (%bquote(&list))

The differences between %str and %nrstr (and between %bquote and %nrbquote) are only a matter of which characters are impacted by quoting.  The NR in the function name quotes % and & in addition to all the other characters quoted by %str.

Super User
Posts: 10,683

## Re: compile time or execution time macro quoting function

I would pick up %nrstr()   %nrbquote() is generally for a macro variable .

Super Contributor
Posts: 285

## Re: compile time or execution time macro quoting function

I have inherited programs that have used %nrbquote by default whether there is macro triggers (&, %) or not. So I was wondering %nrstr can be replaced by %nrbquote in macro call at all conditions.
Discussion stats
• 3 replies
• 163 views
• 3 likes
• 3 in conversation