<?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: call execute() vs. direct macro call: Different results in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/call-execute-vs-direct-macro-call-Different-results/m-p/534235#M146563</link>
    <description>&lt;P&gt;The tip in that document, and the answer posted, are slightly off in my opinion.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="tipGenText"&gt;Tip -&lt;SPAN&gt;The following example uses the %NRSTR macro quoting function to mask the macro statement. This function will delay the execution of macro statements until after a step boundary.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;PRE class="codeFragment"&gt;call execute('%nrstr(%sales('||month||'))');&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;The reason is that the I find that you just need to enclose the macro name in the %NRSTR() function call.&amp;nbsp; &amp;nbsp;Mainly because I find it much easier to read and type correctly.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%sales)(',month,')'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that there might still be some rare situations where you need to enclose some of the parameters inside of %NRSTR(), for example if you are referencing a macro variable that will be calculated by other code you have pushed with CALL EXECUTE.&amp;nbsp; But even then I would prefer to quote those independently to make it clearer.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%mymacro)(month=',month,',previous=%nrstr(&amp;amp;result)',')'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 10 Feb 2019 01:00:55 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-02-10T01:00:55Z</dc:date>
    <item>
      <title>call execute() vs. direct macro call: Different results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-execute-vs-direct-macro-call-Different-results/m-p/534209#M146543</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I can't get my head around why calling a macro directly or via call execute() returns different results for below sample code.&lt;/P&gt;
&lt;P&gt;It's clearly a timing issue but I don't get why this is happening. What am I missing?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 187px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27030i5DE2B9FD7C0FC320/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro sample(method);
  %local mvar;
  %let mvar=0;
  data _null_;
    call symputx('mvar','1','l');
    stop;
  run;

  data sample;
    length method $15;
    method="&amp;amp;method";
    var=symget("mvar");
    mvar="&amp;amp;mvar";
  run;

  proc append base=collect data=sample;
  run;

%mend;

%sample(direct)

data _null_;
  rc=dosubl('%sample(dosubl)');
  stop;
run;

data _null_;
  call execute('%sample(call execute)');
  stop;
run;

proc print data=collect;
run;
proc delete data=collect;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Feb 2019 23:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-execute-vs-direct-macro-call-Different-results/m-p/534209#M146543</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-09T23:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: call execute() vs. direct macro call: Different results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-execute-vs-direct-macro-call-Different-results/m-p/534221#M146552</link>
      <description>&lt;P&gt;&amp;nbsp;Sir&amp;nbsp; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&amp;nbsp;delaying should help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call execute('%nrstr(%sample(call execute))');
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Feb 2019 00:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-execute-vs-direct-macro-call-Different-results/m-p/534221#M146552</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-10T00:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: call execute() vs. direct macro call: Different results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-execute-vs-direct-macro-call-Different-results/m-p/534222#M146553</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Initially I wanted to reply to you that I know how to code around it but that I don't understand what's happening. ...and then I've consulted the SAS documentation and actually the "why" is fully explained there - RTM....&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/default/viewer.htm#n1q1527d51eivsn1ob5hnz0yd1hx.htm&amp;nbsp;" target="_blank" rel="noopener"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/default/viewer.htm#n1q1527d51eivsn1ob5hnz0yd1hx.htm&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hmm... I guess I have to become more careful using call execute() for macro calls when I just want these calls to behave the same as if I'd call the macro directly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 00:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-execute-vs-direct-macro-call-Different-results/m-p/534222#M146553</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-10T00:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: call execute() vs. direct macro call: Different results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-execute-vs-direct-macro-call-Different-results/m-p/534223#M146554</link>
      <description>&lt;P&gt;Oh i'm sorry&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 00:35:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-execute-vs-direct-macro-call-Different-results/m-p/534223#M146554</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-10T00:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: call execute() vs. direct macro call: Different results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-execute-vs-direct-macro-call-Different-results/m-p/534235#M146563</link>
      <description>&lt;P&gt;The tip in that document, and the answer posted, are slightly off in my opinion.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="tipGenText"&gt;Tip -&lt;SPAN&gt;The following example uses the %NRSTR macro quoting function to mask the macro statement. This function will delay the execution of macro statements until after a step boundary.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;PRE class="codeFragment"&gt;call execute('%nrstr(%sales('||month||'))');&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;The reason is that the I find that you just need to enclose the macro name in the %NRSTR() function call.&amp;nbsp; &amp;nbsp;Mainly because I find it much easier to read and type correctly.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%sales)(',month,')'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that there might still be some rare situations where you need to enclose some of the parameters inside of %NRSTR(), for example if you are referencing a macro variable that will be calculated by other code you have pushed with CALL EXECUTE.&amp;nbsp; But even then I would prefer to quote those independently to make it clearer.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%mymacro)(month=',month,',previous=%nrstr(&amp;amp;result)',')'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 01:00:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-execute-vs-direct-macro-call-Different-results/m-p/534235#M146563</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-10T01:00:55Z</dc:date>
    </item>
  </channel>
</rss>

