<?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: Error with nested Macros in Autocall-Library Members in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-with-nested-Macros-in-Autocall-Library-Members/m-p/510989#M137515</link>
    <description>&lt;P&gt;When you want to create a "function style" macro, do not use %put. %put writes messages to the log, but leaves nothing in the code execution queue. Write your macro like this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro upper_limit_loop(inval=);
&amp;amp;inval
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the whole construct will run:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro upper_limit_loop(inval=);
&amp;amp;inval
%mend;

%macro inner_m;
%let inner_out = HIER DER TEXT DES INNEREN MACROS  ;
%do i=1 %to &amp;amp;obergrenze.;
%put &amp;amp;i: &amp;amp;inner_out;
%end;
%mend;

%macro outer_m;
%let outer_out = DAS IST DER TEXT, WELCHER IM AEUSSEREN MACRO DURCHLÄUFT ;
%let obergrenze = %upper_limit_loop(inval=10);
%do j=1 %to 10;
  %put &amp;amp;j: &amp;amp;outer_out;
  %inner_m;
%end;
%mend;

%outer_m&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Nov 2018 09:57:39 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-11-07T09:57:39Z</dc:date>
    <item>
      <title>Error with nested Macros in Autocall-Library Members</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-nested-Macros-in-Autocall-Library-Members/m-p/510977#M137512</link>
      <description>&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have three Macros "outer_m", "inner_m" and "upper_limit_loop". "inner_m" is nested in "outer_m". See here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO outer_m;

%LET outer_out = DAS IST DER TEXT, WELCHER IM AEUSSEREN MACRO DURCHLÄUFT ;
%*let obergrenze = %upper_limit_loop(inval=10);

%MACRO inner_m;
%LET inner_out = HIER DER TEXT DES INNEREN MACROS  ;

%do i=1 %TO 10 /*&amp;amp;obergrenze.*/;
%PUT &amp;amp;i: &amp;amp;inner_out;
%END;
%MEND;

%do j=1 %TO 10;
%PUT &amp;amp;j: &amp;amp;outer_out;
%inner_m;
%END;

%MEND;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have saved the two files "outer_m.sas" and "upper_limit_loop.sas" in a directory&amp;nbsp; /this/is/the/path/for/autocall/.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then tell SAS the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename Macros "/this/is/the/path/for/autocall/" ;
options mautolocdisplay mautosource sasautos = (sasautos, Macros) /*MRECALL*/;

options mprint mprintnest mlogic mlogicnest mcompilenote=ALL ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Everything works perfect. SAS writes in the log, that it compiled the macros from the autocall library, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I replace the hard coded "10" in the Do-Loop with Index "i" and use a macro variable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let obergrenze = %upper_limit_loop(inval=10);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;which shell bel resolved by running another macro, which is also in the autocall-library, I get the following Error:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;ERROR: %EVAL function has no expression to evaluate, or %IF statement has no condition.&lt;BR /&gt;ERROR: The %TO value of the %DO I loop is invalid.&lt;BR /&gt;ERROR: The macro INNER_M will stop executing.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obviously, the macrovariable cannot be resolved! But is it, because it has to call another member, i.e. another macro, within the autocall library or do I have some sort of syntax error?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Generally I would like to know:&lt;/P&gt;&lt;P&gt;Is it possible to nest macros, which are all seperately saved within a autocall-library-path, this way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for any helpful advice on this matter in advance,&lt;/P&gt;&lt;P&gt;FK1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 09:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-nested-Macros-in-Autocall-Library-Members/m-p/510977#M137512</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2018-11-07T09:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: Error with nested Macros in Autocall-Library Members</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-nested-Macros-in-Autocall-Library-Members/m-p/510980#M137513</link>
      <description>&lt;P&gt;First of all, nested macro definitions make no sense and only serve to cause confusion. All macros are defined globally.&lt;/P&gt;
&lt;P&gt;So your code should be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO inner_m;
%LET inner_out = HIER DER TEXT DES INNEREN MACROS  ;

%do i=1 %TO 10 /*&amp;amp;obergrenze.*/;
%PUT &amp;amp;i: &amp;amp;inner_out;
%END;
%MEND;

%MACRO outer_m;

%LET outer_out = DAS IST DER TEXT, WELCHER IM AEUSSEREN MACRO DURCHLÄUFT ;
%*let obergrenze = %upper_limit_loop(inval=10);

%do j=1 %TO 10;
%PUT &amp;amp;j: &amp;amp;outer_out;
%inner_m;
%END;

%MEND;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The crucial information missing here is the code for %upper_limit_loop. Please supply it.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 09:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-nested-Macros-in-Autocall-Library-Members/m-p/510980#M137513</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-07T09:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Error with nested Macros in Autocall-Library Members</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-nested-Macros-in-Autocall-Library-Members/m-p/510988#M137514</link>
      <description>&lt;P&gt;Hello Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I absolutely agree with you, that it is a bad practice to nest macros. However, I was still curious as to why it does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found out, that when assigning a value to a macro variable (here "obergrenze"), the compiler recognizes the percent sign and compiles the macro (here: "upper_limit_loop(inval=10)"). It then also resolves the macrovariable "obergrenze" correctly in the do-loop. But it seems that at run-time it is not possible to "switch back" to compiling another time as the value of obergrenze is a macro...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems to be impossible to assign a value in a do-loop at run-time that has to be generated out of a macro...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code for "upper_limit_loop(inval=)" is as follows:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO upper_limit_loop(inval=);

%GLOBAL ul;

%let ul = &amp;amp;inval;

%PUT &amp;amp;ul.;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is it not possible to construct somethine like this?:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO inner_m;
%LET inner_out = HIER DER TEXT DES INNEREN MACROS  ;

%do i=1 %TO %upper_limit_loop(inval=10) ;
%PUT &amp;amp;i: &amp;amp;inner_out;
%END;
%MEND;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 09:53:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-nested-Macros-in-Autocall-Library-Members/m-p/510988#M137514</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2018-11-07T09:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: Error with nested Macros in Autocall-Library Members</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-with-nested-Macros-in-Autocall-Library-Members/m-p/510989#M137515</link>
      <description>&lt;P&gt;When you want to create a "function style" macro, do not use %put. %put writes messages to the log, but leaves nothing in the code execution queue. Write your macro like this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro upper_limit_loop(inval=);
&amp;amp;inval
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the whole construct will run:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro upper_limit_loop(inval=);
&amp;amp;inval
%mend;

%macro inner_m;
%let inner_out = HIER DER TEXT DES INNEREN MACROS  ;
%do i=1 %to &amp;amp;obergrenze.;
%put &amp;amp;i: &amp;amp;inner_out;
%end;
%mend;

%macro outer_m;
%let outer_out = DAS IST DER TEXT, WELCHER IM AEUSSEREN MACRO DURCHLÄUFT ;
%let obergrenze = %upper_limit_loop(inval=10);
%do j=1 %to 10;
  %put &amp;amp;j: &amp;amp;outer_out;
  %inner_m;
%end;
%mend;

%outer_m&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 09:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-with-nested-Macros-in-Autocall-Library-Members/m-p/510989#M137515</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-07T09:57:39Z</dc:date>
    </item>
  </channel>
</rss>

