BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
djbateman
Lapis Lazuli | Level 10

I was just recently exposed to %NRSTR, so I am not familiar enough to answer my own question.

I used to have a macro that would ask for two stratification labels (STRATLAB1 and STRATLAB2) as well as a group label (GROUPLAB).  My tratification labels used to be FR(++) and FR(+) with a group label being "FR(++) vs. FR(+)".  Our company has now changed the naming convention to be FR(100%) in place of FR(++) and FR(10-90%) in place of FR(+).

My macro call used to look like this (This is very simplified.  My actual macro actually receives up to 25 parameters.):

%efficacyreport(stratlab1=%str(FR(++)), stratlab2=%str(FR(+)), grouplab1=%nrstr(FR(++) vs. FR(+)));

Now, I am trying to run it like this, which is giving me errors:

%efficacyreport(stratlab1=%nrstr(FR(100%)), stratlab2=%nrstr(FR(10-90%)), grouplab1=%nrstr(FR(100%) vs. FR(10-90%)));

Can someone tell me if I have a syntax error?  I assume it is the % within the %NRSTR that is causing the problem becuase when I call the macro, the SAS log will not do anything (no errors, no warnings, no notes), and I cannot run other code.  If I run ); four times, then it spits out errors:

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,

              a missing value, INPUT, PUT.

The code inside the macro that is causing this macro looks like this (nothing wrong syntactically):

data efficacy;

      set &efficacydata.;

      strata=&strata.;

      survtime=&survtime.;

      censorflag=&censorflag.;

run;

where &efficacydata, &strata, &survtime, and &censorflag are input parameters with the macro.  The error message has the semi-colons underlined with a 22, and then gives me the ERROR 22-322 message.  I am sure that is has something to do with my % signs within the %NRSTR function.  This is why I have to submit ); four times to close the macro call.

Any thoughts?


1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

dj,

Inside the %str and %nrstr functions, special characters require special handling.  You found one of them:  % should be referred to as %%.  However, others are in this category as well.  ( should be referred to as %(, and ) as %).  So technically, your original macro calls should have used:

stratlab1=%str(FR%(++%)),

However, when the parentheses are balanced, you can often get away with omitting the % before them.  Once you added %, intending it to be a literal character, you actually changed the right parentheses by referring to it as %).  Now the parentheses appear to macro language to be unbalanced.  I consider it amazing that you actually figured out to add )))) to be able to continue processing.

Hope this helps!

View solution in original post

2 REPLIES 2
djbateman
Lapis Lazuli | Level 10

Someone can correct me if I am wrong, but it looks like I have to have two % signs instead of one.  I did that, and the macro ran fine.  But can someone explain to me why that is?

Astounding
PROC Star

dj,

Inside the %str and %nrstr functions, special characters require special handling.  You found one of them:  % should be referred to as %%.  However, others are in this category as well.  ( should be referred to as %(, and ) as %).  So technically, your original macro calls should have used:

stratlab1=%str(FR%(++%)),

However, when the parentheses are balanced, you can often get away with omitting the % before them.  Once you added %, intending it to be a literal character, you actually changed the right parentheses by referring to it as %).  Now the parentheses appear to macro language to be unbalanced.  I consider it amazing that you actually figured out to add )))) to be able to continue processing.

Hope this helps!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 2 replies
  • 3058 views
  • 4 likes
  • 2 in conversation