<?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 Var resolution: Timing issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469870#M120240</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The late&amp;nbsp;Roland Rashleigh-Berry recommended: &lt;A href="http://www.datasavantconsulting.com/roland/call_exec.html" target="_blank"&gt;Use %nrstr() when you "call execute" a macro&lt;/A&gt;. And indeed, if you follow this advice the warning does not occur. What he wrote seems to explain what you have observed: "&lt;SPAN&gt;&lt;EM&gt;the macro call will be resolved internally&lt;/EM&gt;" already within the data step containing the CALL EXECUTE statement. So, when the macro processor parses the code of macro TESTIT it stumbles across macro variable reference &amp;amp;MyMvar, hence the warning, because the data step defining MyMvar has not been executed yet (as macro resolution has not yet finished plus we are still in the "outer" data step).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;With DOSUBL it's a different story because of the "parallel processing" even of data steps which it enables.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jun 2018 10:24:35 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2018-06-13T10:24:35Z</dc:date>
    <item>
      <title>Macro Var resolution: Timing issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469857#M120232</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I try to understand why in below sample macro variable MyMvar doesn't resolve when using call execute().&lt;/P&gt;
&lt;P&gt;I understand that this is a timing issue but as simple as the example is, I can't understand the why. Could someone please shed some light on it for me?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro testit();
  data _null_;
    call symputx('MyMvar','Test String','L');
    stop;
  run;

  data _null_;
    put "MyMvar: &amp;amp;MyMvar";
    stop;
  run; 

%mend;

data _null_;
  call execute('%testit()');
  stop;
run;

data _null_;
  _rc=dosubl('%testit()');
  stop;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;40         data _null_;
41           call execute('%testit()');
42           stop;
43         run;

WARNING: Apparent symbolic reference MYMVAR not resolved.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

NOTE: CALL EXECUTE generated line.
1         + data _null_;     call symputx('MyMvar','Test String','L');     stop;   run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      
1         +                                                                                data _null_;     put "MyMvar: &amp;amp;MyMvar";  
         stop;   run;


MyMvar: Test String
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Patrick&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 09:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469857#M120232</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-06-13T09:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Var resolution: Timing issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469865#M120235</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;See Tom's answer to the following topic :&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Macro-variable-not-getting-resolved-when-use-Call-execute/td-p/246980" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Macro-variable-not-getting-resolved-when-use-Call-execute/td-p/246980&lt;/A&gt;</description>
      <pubDate>Wed, 13 Jun 2018 10:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469865#M120235</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-06-13T10:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Var resolution: Timing issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469870#M120240</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The late&amp;nbsp;Roland Rashleigh-Berry recommended: &lt;A href="http://www.datasavantconsulting.com/roland/call_exec.html" target="_blank"&gt;Use %nrstr() when you "call execute" a macro&lt;/A&gt;. And indeed, if you follow this advice the warning does not occur. What he wrote seems to explain what you have observed: "&lt;SPAN&gt;&lt;EM&gt;the macro call will be resolved internally&lt;/EM&gt;" already within the data step containing the CALL EXECUTE statement. So, when the macro processor parses the code of macro TESTIT it stumbles across macro variable reference &amp;amp;MyMvar, hence the warning, because the data step defining MyMvar has not been executed yet (as macro resolution has not yet finished plus we are still in the "outer" data step).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;With DOSUBL it's a different story because of the "parallel processing" even of data steps which it enables.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 10:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469870#M120240</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-06-13T10:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Var resolution: Timing issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469872#M120241</link>
      <description>&lt;P&gt;CALL EXECUTE is generating two DATA steps.&amp;nbsp; However, it can't actually run either of them immediately.&amp;nbsp; Both of them have to wait until the current DATA step (the one that contains CALL EXECUTE) has finished.&amp;nbsp; Naturally, you just can't run another DATA step until the current DATA step has finished.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead, SAS has to stack up the statements that CALL EXECUTE is generating, until the current DATA step has finished.&amp;nbsp; There's a problem stacking up the PUT statement, because &amp;amp;MYVAR doesn't exist yet.&amp;nbsp; It only exists after the current DATA step finishes, and the first generated DATA step completes.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 10:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469872#M120241</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-06-13T10:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Var resolution: Timing issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469884#M120244</link>
      <description>&lt;P&gt;You might see it like that: call execute() pushes the code contained onto the same execution pipeline that the current data step is running in, while dosubl() creates a new, independent execution pipeline that only exists for the duration of the dosubl() call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I read it correctly, dosubl() has been added with SAS 9.4 and opens up a whole new way of thinking about timing. At least I can't find a reference in the docs for 9.3 and earlier.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 11:23:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469884#M120244</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-13T11:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Var resolution: Timing issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469893#M120246</link>
      <description>&lt;P&gt;You've already received some great answers.&amp;nbsp; Just to add a bit, I think the key idea is that when you use CALL EXECUTE to invoke a macro, it will execute the macro.&amp;nbsp; When the macro executes, it will generate any SAS code (data step code or whatever), resolve all the macro references, and put it on the input stack to be compiled and executed by the SAS data step compiler.&amp;nbsp; When the macro executes, it will also execute any macro statements immediately.&amp;nbsp; This causes the timing problem, because if the macro generates macro variables from data step code, the attempt to resolve the macro variables will be made before the macro variables have been generated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use CALL EXECUTE to invoke a macro and hide the macro call in %NRSTR(), CALL EXECUTE will not actually execute the macro.&amp;nbsp; Instead, it just generates the call to the macro and puts the macro call on on the input stack.&amp;nbsp; The macro is executed after the data step with the call execute has completed.&amp;nbsp; This lets the timing work out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is slightly revised sample code, with a %PUT statement added&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro testit();
  data _null_;
    call symputx('MyMvar','Test String','L');
    stop;
  run;

  %put Macro %nrstr(%put) MyMVar: &amp;amp;MyMVar ;

  data _null_;
    put "Data step put MyMvar: &amp;amp;MyMvar";
    stop;
  run; 

%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you run it like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%symdel MyMvar ;

data _null_;
  call execute('%testit()');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log shows that call execute generated the SAS code generated by %testit. So it executed %testit:&lt;/P&gt;
&lt;PRE&gt;208  data _null_;
209    call execute('%testit()');
210  run;

WARNING: Apparent symbolic reference MYMVAR not resolved.
Macro %put MyMVar: &amp;amp;MyMVar
WARNING: Apparent symbolic reference MYMVAR not resolved.

NOTE: CALL EXECUTE generated line.
1   + data _null_;     call symputx('MyMvar','Test String','L');     stop;   run;


1   +                                                                                data _null_;
    put "Data step put MyMvar: &amp;amp;MyMvar";     stop;   run;

Data step put MyMvar: Test String
&lt;/PRE&gt;
&lt;P&gt;Warnings are thrown indicating that &amp;amp;MYMVAR could not resolve on the %PUT statement, or the first time it is seen on the PUT statement.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, note that even though you asked CALL SYMPUTX to make a local macro variable, it still made a global macro variable. Because when CALL SYMPUTX executed, there was no local scope.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you run like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%symdel MyMvar ;

data _null_;
  call execute('%nrstr(%testit())');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Call execute will generate the macro call, but won't actually execute the macro.&amp;nbsp; The log shows:&lt;/P&gt;
&lt;PRE&gt;292  data _null_;
293    call execute('%nrstr(%testit())');
294  run;


NOTE: CALL EXECUTE generated line.
1   + %testit()


Macro %put MyMVar: Test String

Data step put MyMvar: Test String
&lt;/PRE&gt;
&lt;P&gt;Note that call executed generated the call to %testit, but did not actually executed %testit.&amp;nbsp; %Testit is executed after the data step with the call execute. So all the timing issues work out.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I always use %NRSTR() when invoking a macro via call execute.&amp;nbsp; Not only does it make the macro timing work out, it also makes a cleaner log, where you can see the macro calls that were generated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 12:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469893#M120246</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-06-13T12:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Var resolution: Timing issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469908#M120255</link>
      <description>&lt;P&gt;Patrick,&lt;/P&gt;
&lt;P&gt;I think&amp;nbsp;@FreelanceReinhar get the point ,add %nrstr() to suppress the warning .&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 12:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/469908#M120255</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-06-13T12:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Var resolution: Timing issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/470500#M120421</link>
      <description>&lt;P&gt;Thank you all for your great answers.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2018 01:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Var-resolution-Timing-issue/m-p/470500#M120421</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-06-15T01:40:40Z</dc:date>
    </item>
  </channel>
</rss>

