<?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: %Eval Macro Funciton within call symput x in a macro enviroment. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Eval-Macro-Funciton-within-call-symput-x-in-a-macro-enviroment/m-p/888376#M350995</link>
    <description>&lt;P&gt;If you turn on SYMBOLGEN option (and perhaps MLOGIC) option you will see more messages in the log showing what the macro processor is doing.&amp;nbsp; (I do not recommend turning those on except for debugging the macro code because your log will become unreadable.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just step through it yourself and see what it is doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data crap.hatchery;
%do index= 1 %to 3;
%put NOTE: &amp;amp;Eggs.;
Larva +1;
%let Eggs = %eval(&amp;amp;Eggs. - 1);
call symputx("Larva", Larva);
%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It generates a DATA statement.&lt;/P&gt;
&lt;P&gt;Then the %DO runs.&amp;nbsp; So when INDEX=1 it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;writes a note to the log.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;generates a SUM statement.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;increments the macro variable EGGS.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;generates a CALL SYMPUTX() statement.&amp;nbsp; &lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Then it does the same thing two more times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally it generates the RUN statement so the data step can start being compiled and run.&lt;/P&gt;
&lt;P&gt;The resulting data step is kind of silly looking and does not seem to have any purpose.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data crap.hatchery;
Larva +1;
call symputx("Larva", Larva);
Larva +1;
call symputx("Larva", Larva);
Larva +1;
call symputx("Larva", Larva);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So all it does is create a dataset with one observation and one variable named LARVA with a value of 3.&amp;nbsp; It also sets the macro variable named LARVA to the digit 3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Aug 2023 14:21:55 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-08-08T14:21:55Z</dc:date>
    <item>
      <title>%Eval Macro Funciton within call symput x in a macro enviroment.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-Macro-Funciton-within-call-symput-x-in-a-macro-enviroment/m-p/888306#M350979</link>
      <description>&lt;DIV&gt;Hello,&lt;/DIV&gt;&lt;DIV&gt;I have been trying to update the macro variable egg with each iteration of my loop using call symputx and %sysevalf. It did not work, instead the macro variable Eggs remained constant.&amp;nbsp; I could possibly update the macro variable with a %let statement (&lt;SPAN&gt; %let Eggs = %eval(&amp;amp;Eggs. - 1);). Yet I was wondering, why it did not work with the symputx call.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%macro Hatchery (Eggs = 6);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%if &amp;amp;Eggs. &amp;gt; 0 %then %do;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;data crap.hatchery;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;/* %do %until (&amp;amp;Eggs. &amp;lt; 1); */&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;%do index= 1 %to 3;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;%put NOTE: &amp;amp;Eggs.;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Larva +1;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;call symputx("Eggs", %sysevalf(&amp;amp;Eggs. - 1));&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;call symputx("Larva", Larva);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;%end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%mend Hatchery;&lt;/DIV&gt;</description>
      <pubDate>Tue, 08 Aug 2023 09:32:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-Macro-Funciton-within-call-symput-x-in-a-macro-enviroment/m-p/888306#M350979</guid>
      <dc:creator>ifb10</dc:creator>
      <dc:date>2023-08-08T09:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval Macro Funciton within call symput x in a macro enviroment.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-Macro-Funciton-within-call-symput-x-in-a-macro-enviroment/m-p/888317#M350982</link>
      <description>&lt;P&gt;I suggest to run your macro using this statement before calling the macro&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Some basic rules on macro processing:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The macro facility produces text that the compiler will process later&lt;/LI&gt;
&lt;LI&gt;Macro statements and functions are executed before the DATA step compiles/executes&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;You are mixing DATA step logic with macro processing logic. Just use DATA step programming for your loop.&lt;/P&gt;
&lt;P&gt;Are you looking for something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let eggs = 4;

data hatchery;
  eggs = &amp;amp;eggs;

  do until (Eggs &amp;lt; 1);
    putlog "NOTE: " eggs=;
    eggs = eggs - 1;
    Larva +1;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Aug 2023 11:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-Macro-Funciton-within-call-symput-x-in-a-macro-enviroment/m-p/888317#M350982</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2023-08-08T11:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval Macro Funciton within call symput x in a macro enviroment.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-Macro-Funciton-within-call-symput-x-in-a-macro-enviroment/m-p/888328#M350985</link>
      <description>&lt;P&gt;Since you never&amp;nbsp;&lt;U&gt;assign&lt;/U&gt; a new value to the macro variable eggs, it will stay at 6 (or whatever value you use in the macro call) throughout, and the result of the %SYSEVALF will always be 5.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 12:21:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-Macro-Funciton-within-call-symput-x-in-a-macro-enviroment/m-p/888328#M350985</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-08T12:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval Macro Funciton within call symput x in a macro enviroment.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-Macro-Funciton-within-call-symput-x-in-a-macro-enviroment/m-p/888336#M350986</link>
      <description>&lt;P&gt;Since the only place you are changing the value of EGGS is with data step code the value of EGGS will not change until after the data step start running.&amp;nbsp;The data step will not start running until after it has been fully defined.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once the macro %DO loop is finished&amp;nbsp; running your data step is going to look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data crap.hatchery;
Larva +1;
call symputx("Eggs", 5);
call symputx("Larva", Larva);
Larva +1;
call symputx("Eggs", 5);
call symputx("Larva", Larva);
Larva +1;
call symputx("Eggs", 5);
call symputx("Larva", Larva);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I do not see why you need any macro logic here at all.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Hatchery (Eggs = 6);
data crap.hatchery;
  do eggs=&amp;amp;eggs to 0 by -1;
    Larva +1;
    output;
 end;
run;
%mend Hatchery;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Aug 2023 12:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-Macro-Funciton-within-call-symput-x-in-a-macro-enviroment/m-p/888336#M350986</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-08T12:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval Macro Funciton within call symput x in a macro enviroment.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-Macro-Funciton-within-call-symput-x-in-a-macro-enviroment/m-p/888370#M350991</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;for the detailed answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The main purpose was to understand the macro logic a bit better.&amp;nbsp; Especially the macro variable definitions in a local environment using proc sql, call symputx and %let statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this regard your answer was perfectly explaining why call symputx can not work under this setting.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yet I was wondering, why does the same logic not apply to the %let statement? I tried following code which did the job:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;%macro Hatchery (Eggs = 6);

data crap.hatchery;
%do index= 1 %to 3;
%put NOTE: &amp;amp;Eggs.;
Larva +1;
%let Eggs = %eval(&amp;amp;Eggs. - 1);
call symputx("Larva", Larva);
%end;
run;
%mend Hatchery;

%Hatchery&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it because the %let statement is directly processed in the macro processor and the symbol table is immediately updated after each iteration? I guess in contrast to that I get similar results to call symputx with proc sql select into clause as you described. My guess is that Macro processor is not triggered by either call symputx nor select into (proc sql) which are instead resolved as you described only after compilation.&amp;nbsp;&lt;/P&gt;&lt;PRE class=""&gt;&lt;CODE&gt;data crap.hatchery;
Larva +1;
call symputx("Eggs", 5);
call symputx("Larva", Larva);
Larva +1;
call symputx("Eggs", 5);
call symputx("Larva", Larva);
Larva +1;
call symputx("Eggs", 5);
call symputx("Larva", Larva);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again, now I have only to find out how I can mark your answer as solution as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 14:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-Macro-Funciton-within-call-symput-x-in-a-macro-enviroment/m-p/888370#M350991</guid>
      <dc:creator>ifb10</dc:creator>
      <dc:date>2023-08-08T14:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: %Eval Macro Funciton within call symput x in a macro enviroment.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Eval-Macro-Funciton-within-call-symput-x-in-a-macro-enviroment/m-p/888376#M350995</link>
      <description>&lt;P&gt;If you turn on SYMBOLGEN option (and perhaps MLOGIC) option you will see more messages in the log showing what the macro processor is doing.&amp;nbsp; (I do not recommend turning those on except for debugging the macro code because your log will become unreadable.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just step through it yourself and see what it is doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data crap.hatchery;
%do index= 1 %to 3;
%put NOTE: &amp;amp;Eggs.;
Larva +1;
%let Eggs = %eval(&amp;amp;Eggs. - 1);
call symputx("Larva", Larva);
%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It generates a DATA statement.&lt;/P&gt;
&lt;P&gt;Then the %DO runs.&amp;nbsp; So when INDEX=1 it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;writes a note to the log.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;generates a SUM statement.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;increments the macro variable EGGS.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;generates a CALL SYMPUTX() statement.&amp;nbsp; &lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Then it does the same thing two more times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally it generates the RUN statement so the data step can start being compiled and run.&lt;/P&gt;
&lt;P&gt;The resulting data step is kind of silly looking and does not seem to have any purpose.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data crap.hatchery;
Larva +1;
call symputx("Larva", Larva);
Larva +1;
call symputx("Larva", Larva);
Larva +1;
call symputx("Larva", Larva);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So all it does is create a dataset with one observation and one variable named LARVA with a value of 3.&amp;nbsp; It also sets the macro variable named LARVA to the digit 3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 14:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Eval-Macro-Funciton-within-call-symput-x-in-a-macro-enviroment/m-p/888376#M350995</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-08T14:21:55Z</dc:date>
    </item>
  </channel>
</rss>

