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))
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.
I would pick up %nrstr() %nrbquote() is generally for a macro variable .
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.