BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ifendo
Obsidian | Level 7

Hi,

 

i am trying the basic macro facility. While i tried to submit below the code:

 

%let param=%nrstr(%RO CD8+NK+ (%));
%put &param;

 

the SAS 9.4 get stuck.

however,below codes worked

%let param=%nrstr(%%RO CD8+NK+ (%%));
%put &param;

 

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
jklaverstijn
Rhodochrosite | Level 12

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.

View solution in original post

8 REPLIES 8
jklaverstijn
Rhodochrosite | Level 12

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

ifendo
Obsidian | Level 7

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?

 

 

ifendo
Obsidian | Level 7

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

jklaverstijn
Rhodochrosite | Level 12

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.

ifendo
Obsidian | Level 7

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;

jklaverstijn
Rhodochrosite | Level 12

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.
ifendo
Obsidian | Level 7

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

ballardw
Super User

@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 &param to be.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1854 views
  • 0 likes
  • 3 in conversation