BookmarkSubscribeRSS Feed
Kevin_Viel
Obsidian | Level 7

How can I avoid the Warnings that an apparent symbolic reference is not resolved when the macro parameter value contains a reference to another macro parameter:

 

 

12701         , label_at_risk                    = Number of Patients at risk
WARNING: Apparent symbolic reference TREAT_GROUP_VAR not resolved.
12702      
12703         , xaxis_labelattrs_weight          = bold
WARNING: Apparent symbolic reference TIMELIST_UNITS not resolved.
12704         , yaxis_labelattrs_weight          = bold
12705      
12706         , lifetest_quartiles_inset_label   = cat( strip( &treat_group_var. )
12707                                                 %str(,) " median Overall Survival [&timelist_units.] (95% CI) = "
WARNING: Apparent symbolic reference TREAT_GROUP_VAR not resolved.
12708                                                 )
12709      
12710         , phreg_inset_label                = cat( "HR (95% CI) ["
12711                                                 %str(,) strip( prxchange( "s/^&treat_group_var.//i"
12712                                                                   %str(,) 1
12713                                                                   %str(,) left( description )
12714                                                                   )
12715                                                        )
12716                                                 , "] = "
12717                                                 )

The value that I specified for the macro parameters LIFETEST_QUARTILES_INSET_LABEL and PHREG_INSET_LABEL use other macro parameters.  I could just provide the value of, say, TREAT_GROUP_VAR, but I was being lazy, I mean, expeditious.  Well, it seems better to just change the value once.  I note that when I use the macro with the default values for these variables, which use the same macro parameters as this example, I did not get the Warnings.

 

I was wondering if I could mask the ampersand in the value, but have it properly resolve in macro execution.  I failed this question previously, but it is really bugging me now.

 

Thank you,

 

Kevin

 

2 REPLIES 2
Quentin
Super User

Hi Kevin,

 

The challenge is that when you call a macro any macro variable references in the macro invocation are resolved before the macro is invoked.

 

So:

%macro try(x=,y=) ;
  %put &=x &=y ;
%mend try ;

%try(x=3,y=&x)

Might give the right result, but for bad reasons.  SAS tries to resolve &x during the macro call but it can't, so it throws the warning, and the local macro variable Y will have the value &x  (rather than the value 3).

 

One option is to use %nrstr() to hide the & sign in the macro variable reference in the invocation, but then you need to %unquote the value inside the macro to get it to resolve.  So something like this can work:

 

%macro try(x=,y=) ;
  %let y=%unquote(&y) ;
  %put &=x &=y ;
%mend try ;

%try(x=9,y=%nrstr(&x))

I don't love that approach.  But I've used it.

 

As you say, when you use the macro reference in a default value, you don't have to jump through these hoops, because the macro reference is not actually seen in the macro call.  So below works fine:

%macro try(x=,y=&x) ;
  %put _local_ ;
  %put &=x &=y ;
%mend try ;

%try(x=0)

As seen from the %put _local_, the local macro variable y will have the default value &x.  But when y is referenced in the macro, it will first resolve to &x, which will then resolve.  So it can work as a way to make y an indirect reference to the value of x.

 

HTH,

--Q.

 

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in March 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 1126 views
  • 6 likes
  • 3 in conversation