<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: MACRO parameter / values containing other macro parameters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MACRO-parameter-values-containing-other-macro-parameters/m-p/767814#M243465</link>
    <description>&lt;P&gt;Hi Kevin,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The challenge is that when you call a macro any macro variable references in the macro invocation are resolved before the macro is invoked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro try(x=,y=) ;
  %put &amp;amp;=x &amp;amp;=y ;
%mend try ;

%try(x=3,y=&amp;amp;x)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Might give the right result, but for bad reasons.&amp;nbsp; SAS tries to resolve &amp;amp;x during the macro call but it can't, so it throws the warning, and the local macro variable Y will have the value &amp;amp;x&amp;nbsp; (rather than the value 3).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One option is to use %nrstr() to hide the &amp;amp; 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.&amp;nbsp; So something like this can work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro try(x=,y=) ;
  %let y=%unquote(&amp;amp;y) ;
  %put &amp;amp;=x &amp;amp;=y ;
%mend try ;

%try(x=9,y=%nrstr(&amp;amp;x))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I don't love that approach.&amp;nbsp; But I've used it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp; So below works fine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro try(x=,y=&amp;amp;x) ;
  %put _local_ ;
  %put &amp;amp;=x &amp;amp;=y ;
%mend try ;

%try(x=0)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As seen from the %put _local_, the local macro variable y will have the default value &amp;amp;x.&amp;nbsp; But when y is referenced in the macro, it will first resolve to &amp;amp;x, which will then resolve.&amp;nbsp; So it can work as a way to make y an indirect reference to the value of x.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;--Q.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Sep 2021 01:55:14 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2021-09-15T01:55:14Z</dc:date>
    <item>
      <title>MACRO parameter / values containing other macro parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-parameter-values-containing-other-macro-parameters/m-p/767808#M243461</link>
      <description>&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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( &amp;amp;treat_group_var. )
12707                                                 %str(,) " median Overall Survival [&amp;amp;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/^&amp;amp;treat_group_var.//i"
12712                                                                   %str(,) 1
12713                                                                   %str(,) left( description )
12714                                                                   )
12715                                                        )
12716                                                 , "] = "
12717                                                 )
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The value that I specified for the macro parameters LIFETEST_QUARTILES_INSET_LABEL and PHREG_INSET_LABEL use other macro parameters.&amp;nbsp; I could just provide the value of, say, TREAT_GROUP_VAR, but I was being lazy, I mean, expeditious.&amp;nbsp; Well, it seems better to just change the value once.&amp;nbsp; 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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was wondering if I could mask the ampersand in the value, but have it properly resolve in macro execution.&amp;nbsp; I failed this question previously, but it is really bugging me now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kevin&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 23:58:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-parameter-values-containing-other-macro-parameters/m-p/767808#M243461</guid>
      <dc:creator>Kevin_Viel</dc:creator>
      <dc:date>2021-09-14T23:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO parameter / values containing other macro parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-parameter-values-containing-other-macro-parameters/m-p/767812#M243463</link>
      <description>&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/vdmmlcdc/1.0/mcrolref/n1mm3jwlbolg00n1b7w7aiybuch8.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/vdmmlcdc/1.0/mcrolref/n1mm3jwlbolg00n1b7w7aiybuch8.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use symexist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 01:39:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-parameter-values-containing-other-macro-parameters/m-p/767812#M243463</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2021-09-15T01:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO parameter / values containing other macro parameters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-parameter-values-containing-other-macro-parameters/m-p/767814#M243465</link>
      <description>&lt;P&gt;Hi Kevin,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The challenge is that when you call a macro any macro variable references in the macro invocation are resolved before the macro is invoked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro try(x=,y=) ;
  %put &amp;amp;=x &amp;amp;=y ;
%mend try ;

%try(x=3,y=&amp;amp;x)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Might give the right result, but for bad reasons.&amp;nbsp; SAS tries to resolve &amp;amp;x during the macro call but it can't, so it throws the warning, and the local macro variable Y will have the value &amp;amp;x&amp;nbsp; (rather than the value 3).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One option is to use %nrstr() to hide the &amp;amp; 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.&amp;nbsp; So something like this can work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro try(x=,y=) ;
  %let y=%unquote(&amp;amp;y) ;
  %put &amp;amp;=x &amp;amp;=y ;
%mend try ;

%try(x=9,y=%nrstr(&amp;amp;x))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I don't love that approach.&amp;nbsp; But I've used it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp; So below works fine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro try(x=,y=&amp;amp;x) ;
  %put _local_ ;
  %put &amp;amp;=x &amp;amp;=y ;
%mend try ;

%try(x=0)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As seen from the %put _local_, the local macro variable y will have the default value &amp;amp;x.&amp;nbsp; But when y is referenced in the macro, it will first resolve to &amp;amp;x, which will then resolve.&amp;nbsp; So it can work as a way to make y an indirect reference to the value of x.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;--Q.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 01:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-parameter-values-containing-other-macro-parameters/m-p/767814#M243465</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2021-09-15T01:55:14Z</dc:date>
    </item>
  </channel>
</rss>

