Hi,
i am trying the basic macro facility. While i tried to submit below the code:
%let param=%nrstr(%RO CD8+NK+ (%));
%put ¶m;
the SAS 9.4 get stuck.
however,below codes worked
%let param=%nrstr(%%RO CD8+NK+ (%%));
%put ¶m;
But according to the SAS doc here http://support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/default/viewer.htm#p0pnc7p9n4h6g5n16..., i didn't find where is the problem.
can anybody help to explain this?
thank you very much
I can see why you say "the parenthesis are matched this time". But in fact, by prepending a percent to that last closing paren you still don't have one. That closing paren around the macro parameters is just not safe from being masked. The message you get is clear about that:
ERROR: Expected close parenthesis after macro function invocation not found.
It's the percent sign between parenthesis that are hurting you. That one needs to be doubled up. The doc is clear about this. Percent signs in combination with quotation marks and before a parenthesis need special attention. The first percent sign in your string is okay.
Hope this helps,
- Jan
thanks,Jan. But i still didn't find this "Percent signs in combination with quotation marks and before a parenthesis need special attention" instruction....
Could you please kindly paste the specific sentence from the doc?
Note: If an unmatched single or double quotation mark or an open or close parenthesis is used with %STR or %NRSTR, these characters must be preceded by a percent sign (%).
for above the highlighted part, dose that mean , no matter the open or close parenthesis matched or not, an extra % is needed?
please kindly correct me if i misunderstand anything.
thank you very much
The percent sign is used inside %STR() and %NRSTR() to mask unbalanced quotation marks or parenthesis. Hence your "%)" would be interpreted as "mask the unmatched parenthesis. This leads to a either a message about unbalanced parenthesis (as the closing paren is no longer is matched to its opening sibling) or a seemingly unresponsive EG run. Therefore the need to mask the percent sign itself by adding a second percent sign, eventhough %NRSTR() is described as "masking % signs".
This is all documented in the online doc. There is a paragraph titled "Using Unmatched Quotation Marks and Parentheses with %STR and %NRSTR".
Regards Jan.
got it, thank you. i misunderstood the unmatched concept.
one more question, what's wrong with this case?
%let test=%nrstr(RO CD8+NK+ ()%); *the parenthesis are matched this time, but it didn't work;
%put &test;
%let test1=%nrstr(RO CD8+NK+ ()); *the parenthesis are matched this time, but it works without the last %;
%put &test1;
I can see why you say "the parenthesis are matched this time". But in fact, by prepending a percent to that last closing paren you still don't have one. That closing paren around the macro parameters is just not safe from being masked. The message you get is clear about that:
ERROR: Expected close parenthesis after macro function invocation not found.
i see, thank you for the patience
i didn't get that error if submit this:
%let test=%nrstr(RO CD8+NK+ ()%); *the parenthesis are matched this time, but it didn't work;
%put &test;
but nothing happen in the log and the codes submitted thereafter are not executed as well. ...weird
@ifendo wrote:
i see, thank you for the patience
i didn't get that error if submit this:
%let test=%nrstr(RO CD8+NK+ ()%); *the parenthesis are matched this time, but it didn't work;
%put &test;
but nothing happen in the log and the codes submitted thereafter are not executed as well. ...weird
I don't see anywhere that you have shown us what you actually expect the value of &test or ¶m to be.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.