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!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2247 views
  • 4 likes
  • 2 in conversation