<?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: Use parameter x as part of value of parameter y on macro call in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Use-parameter-x-as-part-of-value-of-parameter-y-on-macro-call/m-p/550647#M7375</link>
    <description>&lt;P&gt;It works because the macro call has caused the macro parser to treat the &amp;amp;&amp;amp; and your macro call as two separate tokens.&amp;nbsp;Normally if you type &amp;amp;&amp;amp;p1 the macro processor will convert &amp;amp;&amp;amp; to &amp;amp; and then continue to resolve the token and try to resolve &amp;amp;p1.&amp;nbsp;But adding the macro call around p1 it does not do that second round of evaluation.&amp;nbsp;So the &amp;amp;p1 is passed into the macro as the value of P2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you should use the %UPCASE() function instead of calling the SAS supplied %LOWCASE() macro.&lt;/P&gt;
&lt;P&gt;Use %UPCASE() instead because that is macro function (part of the actual SAS language).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also the SAS supplied macro %LOWCASE is not that well written.&amp;nbsp; It will cause errors if try to call it with values that contain commas.&lt;/P&gt;
&lt;PRE&gt;567   %put %lowcase(a,b);
ERROR: More positional parameters found than defined.&lt;/PRE&gt;
&lt;P&gt;Here is a replacement for the limited %LOWCASE() macro that SAS sends.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro lowcase/parmbuff;
%if %length(&amp;amp;syspbuff)&amp;gt;2 %then %sysfunc(lowcase&amp;amp;syspbuff);
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;570   %macro lowcase/parmbuff;
571   %if %length(&amp;amp;syspbuff)&amp;gt;2 %then %sysfunc(lowcase&amp;amp;syspbuff);
572   %mend;
573
574
575   %put %lowcase;

576   %put %lowcase();

577   %put %lowcase(a,b);
a,b
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 Apr 2019 14:55:22 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-04-12T14:55:22Z</dc:date>
    <item>
      <title>Use parameter x as part of value of parameter y on macro call</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Use-parameter-x-as-part-of-value-of-parameter-y-on-macro-call/m-p/550600#M7371</link>
      <description>&lt;P&gt;Version =&amp;nbsp;&lt;STRONG&gt;Release: 3.7 (Enterprise Edition)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi, suppose I have this Macro:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(p1,p2);
%put &amp;amp;p1.;
%put &amp;amp;p2.;
%mend test;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And sometimes when I call it, the value of p2 depends on p1:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%test(p1=peas,p2=&amp;amp;p1. and carrots);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This works fine but I receive a warning:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WARNING: Apparent symbolic reference P1 not resolved.
 68         
 69         %test(p1=peas,p2=&amp;amp;p1. and carrots);
 P1=peas
 P2=peas and carrots&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there a way to suppress this warning?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 12:38:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Use-parameter-x-as-part-of-value-of-parameter-y-on-macro-call/m-p/550600#M7371</guid>
      <dc:creator>pepegalleta</dc:creator>
      <dc:date>2019-04-12T12:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: Use parameter x as part of value of parameter y on macro call</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Use-parameter-x-as-part-of-value-of-parameter-y-on-macro-call/m-p/550601#M7372</link>
      <description>&lt;P&gt;When you call the macro via&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%test(p1=peas,p2=&amp;amp;p1. and carrots);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then at this point, &amp;amp;p1 is not defined. So the WARNING is correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could, if you want, do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let word=peas;

%test(p1=&amp;amp;word,p2=&amp;amp;word and carrots)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Apr 2019 12:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Use-parameter-x-as-part-of-value-of-parameter-y-on-macro-call/m-p/550601#M7372</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-12T12:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: Use parameter x as part of value of parameter y on macro call</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Use-parameter-x-as-part-of-value-of-parameter-y-on-macro-call/m-p/550606#M7373</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;And &lt;STRONG&gt;sometimes&lt;/STRONG&gt; when I call it, the value of p2 depends on p1:&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;If it is only sometimes then make that happen in the process of generating the call.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=peas;
%test(p1=&amp;amp;x,p2=&amp;amp;x and carrots)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;You can get that effect if you reference another parameter's value in the default values assigned in DEFINITION of the macro.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(p1=peas,p2=&amp;amp;p1 and carrots);
%put ACTUAL P1=%superq(p1) P2=%superq(p2);
%put RESULT &amp;amp;=p1 &amp;amp;=p2;
%mend test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;276   %test;
ACTUAL P1=peas P2=&amp;amp;p1 and carrots
RESULT P1=peas P2=peas and carrots&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;But if you try to use macro quoting to pass in the &amp;amp;p1 then your macro will have to do something to remove the macro quoting.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(p1,p2);
%put ACTUAL P1=%superq(p1) P2=%superq(p2);
%put RESULT &amp;amp;=p1 &amp;amp;=p2;
%let p1=%unquote(&amp;amp;p1);
%let p2=%unquote(&amp;amp;p2);
%put AFTER &amp;amp;=p1 &amp;amp;=p2;
%mend test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;300   %test(peas,%nrstr(&amp;amp;p1) and carrots);
ACTUAL P1=peas P2=&amp;amp;p1 and carrots
RESULT P1=peas P2=&amp;amp;p1 and carrots
AFTER P1=peas P2=peas and carrots
&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Apr 2019 13:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Use-parameter-x-as-part-of-value-of-parameter-y-on-macro-call/m-p/550606#M7373</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-12T13:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Use parameter x as part of value of parameter y on macro call</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Use-parameter-x-as-part-of-value-of-parameter-y-on-macro-call/m-p/550631#M7374</link>
      <description>&lt;P&gt;Thanks for the answers. I think creating another macrovariable before the macro call is going to be the best approach.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried this, which seems to work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(p1,p2);
  %put &amp;amp;=p1.;
  %put &amp;amp;=p2.; 
%mend;

%test(p1=peas,p2=&amp;amp;&amp;amp;%lowcase(p1) and carrots);&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;69 %macro test(p1,p2);
70 %put &amp;amp;=p1.;
71 %put &amp;amp;=p2.;
72 %mend;
73
74 %test(p1=peas,p2=&amp;amp;&amp;amp;%lowcase(p1) and carrots);
P1=peas
P2=peas and carrots&lt;/PRE&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But why does it work? And why shouldn't I use it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 13:46:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Use-parameter-x-as-part-of-value-of-parameter-y-on-macro-call/m-p/550631#M7374</guid>
      <dc:creator>pepegalleta</dc:creator>
      <dc:date>2019-04-12T13:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: Use parameter x as part of value of parameter y on macro call</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Use-parameter-x-as-part-of-value-of-parameter-y-on-macro-call/m-p/550647#M7375</link>
      <description>&lt;P&gt;It works because the macro call has caused the macro parser to treat the &amp;amp;&amp;amp; and your macro call as two separate tokens.&amp;nbsp;Normally if you type &amp;amp;&amp;amp;p1 the macro processor will convert &amp;amp;&amp;amp; to &amp;amp; and then continue to resolve the token and try to resolve &amp;amp;p1.&amp;nbsp;But adding the macro call around p1 it does not do that second round of evaluation.&amp;nbsp;So the &amp;amp;p1 is passed into the macro as the value of P2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you should use the %UPCASE() function instead of calling the SAS supplied %LOWCASE() macro.&lt;/P&gt;
&lt;P&gt;Use %UPCASE() instead because that is macro function (part of the actual SAS language).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also the SAS supplied macro %LOWCASE is not that well written.&amp;nbsp; It will cause errors if try to call it with values that contain commas.&lt;/P&gt;
&lt;PRE&gt;567   %put %lowcase(a,b);
ERROR: More positional parameters found than defined.&lt;/PRE&gt;
&lt;P&gt;Here is a replacement for the limited %LOWCASE() macro that SAS sends.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro lowcase/parmbuff;
%if %length(&amp;amp;syspbuff)&amp;gt;2 %then %sysfunc(lowcase&amp;amp;syspbuff);
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;570   %macro lowcase/parmbuff;
571   %if %length(&amp;amp;syspbuff)&amp;gt;2 %then %sysfunc(lowcase&amp;amp;syspbuff);
572   %mend;
573
574
575   %put %lowcase;

576   %put %lowcase();

577   %put %lowcase(a,b);
a,b
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 14:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Use-parameter-x-as-part-of-value-of-parameter-y-on-macro-call/m-p/550647#M7375</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-12T14:55:22Z</dc:date>
    </item>
  </channel>
</rss>

