03-18-2018 03:06 PM
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))
03-18-2018 03:47 PM
For this particular example, the answer is "none of the above". This macro call should generate the same result:
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;
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:
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.
03-19-2018 11:56 AM