<?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 with layers of macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723687#M224610</link>
    <description>&lt;P&gt;I usually only wrap the %NRSTR() around the macro reference itself, not the arguments.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%mymacro)(',var1,',',var2,')'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But that can depend on what values you are passing.&amp;nbsp; If you want to have an argument that references a macro variable generated by the running of generated code then quote that reference also.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Mar 2021 22:02:12 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-03-04T22:02:12Z</dc:date>
    <item>
      <title>CALL EXECUTE with layers of macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723352#M224447</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;We have a process where '%ED' macro is executed, which calls 'Template.sas', which in turn calls 'Calculator_ED.sas'.&lt;/P&gt;&lt;P&gt;Inside Calculator.sas there is a macro %createindex, which performs conditional processing based on &amp;amp;classification_option macro variable. &amp;amp;Classification_option is defined through %let statement in 'Template.sas' and equals to &amp;amp;Flag. &amp;amp;Flag value is assigned inside %ED macro.&lt;/P&gt;&lt;P&gt;When I run %ED macro the process works. However, we had to build a 'control' table which determines which process will be run and then %ED macro is invoked through CALL EXECUTE. The addition of this step breaks the process.&lt;/P&gt;&lt;P&gt;Any insights are greatly appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;A simplified process is shown below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I. This works:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;ED&lt;/EM&gt;&lt;/STRONG&gt;(YEAR=&lt;STRONG&gt;20&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;II. This does not work:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;FILENAME ctrl "Path\Test.csv";&lt;/P&gt;&lt;P&gt;* Table contents:&lt;/P&gt;&lt;P&gt;* Macro = ED;&lt;/P&gt;&lt;P&gt;* Year&amp;nbsp; = 20;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; WORK.Control;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FORMAT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Macro&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $CHAR8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Year&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEST2.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; INFILE ctrl&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LRECL=&lt;STRONG&gt;50&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delimiter=','&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MISSOVER&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DSD&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; firstobs=&lt;STRONG&gt;2&lt;/STRONG&gt;;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; INPUT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Macro&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : $CHAR8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Year&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : ?? BEST2.;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; _NULL_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET Control;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arg = cats('%',Macro,'(Year=',Year,')');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CALL execute(arg);&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference ABF_CLASSIFICATION not resolved.&lt;/P&gt;&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&amp;nbsp;&amp;nbsp; &amp;amp;CLASSIFICATION_OPTION. &amp;lt; 3&lt;/P&gt;&lt;P&gt;ERROR: The macro CREATEINDEX will stop executing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Macro ED&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%Macro&lt;/STRONG&gt; ED(YEAR=);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let Model = 'Path\TEMPLATE.sas';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* Flag = 1;&lt;/P&gt;&lt;P&gt;data ED_INPUT;&lt;/P&gt;&lt;P&gt;set Original_data;&lt;/P&gt;&lt;P&gt;where Flag = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%let Flag = 1;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%include "&amp;amp;Model";&lt;/P&gt;&lt;P&gt;data ED_1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set ED_Output;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* Flag = 0;&lt;/P&gt;&lt;P&gt;data ED_INPUT;&lt;/P&gt;&lt;P&gt;set Original_data;&lt;/P&gt;&lt;P&gt;where ABF_Flag = &lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%let Flag = 0;&lt;/P&gt;&lt;P&gt;%include "&amp;amp;Model";&lt;/P&gt;&lt;P&gt;data ED_2;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set ED_Output;run;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%Mend&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;TEMPLATE.sas&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Contains:&lt;/P&gt;&lt;P&gt;%let CLASSIFICATION_OPTION = &amp;amp;Flag;&lt;/P&gt;&lt;P&gt;%include "&amp;amp;LOCATION.\CALCULATOR_ED.sas";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;CALCULATOR_ED.sas&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Contains macro definition and macro call for &lt;STRONG&gt;%macro&lt;/STRONG&gt; &lt;STRONG&gt;&lt;EM&gt;createindex&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;That macro executes conditional processing based on &amp;amp;CLASSIFICATION_OPTION:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if &amp;amp;CLASSIFICATION_OPTION. &amp;lt; &lt;STRONG&gt;3&lt;/STRONG&gt; %then %do;&lt;/P&gt;&lt;P&gt;[actions]&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%else %if &amp;amp;CLASSIFICATION_OPTION. = &lt;STRONG&gt;3&lt;/STRONG&gt; %then %do;&lt;/P&gt;&lt;P&gt;[actions]&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%else %if &amp;amp;CLASSIFICATION_OPTION. = &lt;STRONG&gt;4&lt;/STRONG&gt; %then %do;&lt;/P&gt;&lt;P&gt;[actions]&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 03:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723352#M224447</guid>
      <dc:creator>VSht</dc:creator>
      <dc:date>2021-03-04T03:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: CALL EXECUTE with layers of macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723353#M224448</link>
      <description>&lt;P&gt;Timing.&amp;nbsp; Don't let SAS run the macro will you are pushing it onto the stack to run after the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set control;
  call execute(cats('%nrstr(%',macro,')(year=',year,')'));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the macro call %ED(year=20) will be pushed onto the stack instead of the code that running %ED() generates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus your SAS log will be a lot easier to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 03:52:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723353#M224448</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-04T03:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: CALL EXECUTE with layers of macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723354#M224449</link>
      <description>&lt;P&gt;Thank you!!! Works perfectly and you are right - the log is clear and easy to read.&lt;/P&gt;&lt;P&gt;Should one always add %nrstr when using CALL EXECUTE?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 04:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723354#M224449</guid>
      <dc:creator>VSht</dc:creator>
      <dc:date>2021-03-04T04:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: CALL EXECUTE with layers of macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723444#M224495</link>
      <description>&lt;P&gt;It depends on the code you are pushing with CALL EXECUTE().&lt;/P&gt;
&lt;P&gt;If you are just pushing regular SAS statements then you normally do not care as the macro processor will ignore those strings anyway.&lt;/P&gt;
&lt;P&gt;If actually want the macro to run when the CALL EXECUTE() is running then don't include the %NRSTR().&amp;nbsp; So if the macro call is just going to execute macro statements AND you need the datastep to retrieve the modified macro variable values later in the same step (via other CALL EXECUTE() steps or via SYMGET() function call).&lt;/P&gt;
&lt;P&gt;If the macro does not have conditional logic that depends on the execution of the SAS code that the macro generates then you won't have a timing issue if you leave off the %NRSTR().&amp;nbsp; You will just get a messy SAS log.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 13:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723444#M224495</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-04T13:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: CALL EXECUTE with layers of macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723671#M224602</link>
      <description>I never had this issue before. I have to learn more about this. Your explanation sets me in the right direction. Thank you.</description>
      <pubDate>Thu, 04 Mar 2021 21:42:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723671#M224602</guid>
      <dc:creator>VSht</dc:creator>
      <dc:date>2021-03-04T21:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: CALL EXECUTE with layers of macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723687#M224610</link>
      <description>&lt;P&gt;I usually only wrap the %NRSTR() around the macro reference itself, not the arguments.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%mymacro)(',var1,',',var2,')'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But that can depend on what values you are passing.&amp;nbsp; If you want to have an argument that references a macro variable generated by the running of generated code then quote that reference also.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 22:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723687#M224610</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-04T22:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: CALL EXECUTE with layers of macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723689#M224612</link>
      <description>Tank you. I will definitely experiment with this.:)</description>
      <pubDate>Thu, 04 Mar 2021 22:04:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-EXECUTE-with-layers-of-macros/m-p/723689#M224612</guid>
      <dc:creator>VSht</dc:creator>
      <dc:date>2021-03-04T22:04:41Z</dc:date>
    </item>
  </channel>
</rss>

