<?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 variable not refreshing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488887#M127500</link>
    <description>&lt;P&gt;I am sorry, I cannot post the full code. But in the actual code, the import macro scans the directory and picks one csv file after another.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Even though the csv file changes the value of the macro variables in the actual macro does not change, that is the issue I am facing.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Aug 2018 14:04:41 GMT</pubDate>
    <dc:creator>PJ007</dc:creator>
    <dc:date>2018-08-22T14:04:41Z</dc:date>
    <item>
      <title>Macro variable not refreshing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488724#M127422</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a macro variable inside a macro. The problem is that the value of this macro variable maxnum is not getting refreshed when the macro is executed again in a loop. It is still retaining the old value from the first run of the loop.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro abc;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select max(anumber) into :maxnum&lt;BR /&gt;from&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;table1;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%mend abc;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro import;&lt;/P&gt;&lt;P&gt;%do I=1 %to &amp;amp;totobs. ;&lt;BR /&gt;data _null_;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;set&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;bcf;&lt;BR /&gt;If obs=&amp;amp;i. ;&lt;/P&gt;&lt;P&gt;IF filetype=".csv" THEN call execute ('%abc') ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%MEND Import;&lt;BR /&gt;%Import;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 21:30:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488724#M127422</guid>
      <dc:creator>PJ007</dc:creator>
      <dc:date>2018-08-21T21:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not refreshing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488745#M127429</link>
      <description>&lt;P&gt;Your ABC macro has nothing in it that changes. You an run it a thousand times and it will always do the same thing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 00:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488745#M127429</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-22T00:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not refreshing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488886#M127499</link>
      <description>&lt;P&gt;%macro abc;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select max(anumber) into :maxnum&lt;BR /&gt;from&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;table1;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%mend abc;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro import;&lt;/P&gt;&lt;P&gt;%do I=1 %to &amp;amp;totobs. ;&lt;BR /&gt;data _null_;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;set&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;bcf_directory;&lt;BR /&gt;If obs=&amp;amp;i. ;&lt;/P&gt;&lt;P&gt;IF filetype=".csv" THEN call execute ('%abc') ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%MEND Import;&lt;BR /&gt;%Import;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 14:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488886#M127499</guid>
      <dc:creator>PJ007</dc:creator>
      <dc:date>2018-08-22T14:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not refreshing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488887#M127500</link>
      <description>&lt;P&gt;I am sorry, I cannot post the full code. But in the actual code, the import macro scans the directory and picks one csv file after another.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Even though the csv file changes the value of the macro variables in the actual macro does not change, that is the issue I am facing.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 14:04:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488887#M127500</guid>
      <dc:creator>PJ007</dc:creator>
      <dc:date>2018-08-22T14:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not refreshing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488889#M127502</link>
      <description>&lt;P&gt;You seem to have posted the same code again.&lt;/P&gt;
&lt;P&gt;Note that running %abc macro multiple times in a row will not magically cause it to do anything different if nothing has changed between the runs.&lt;/P&gt;
&lt;P&gt;Perhaps you have over simplified your actual problem?&lt;/P&gt;
&lt;P&gt;In that case you should make sure to use %NRSTR() when calling a macro via CALL EXECUTE() this will prevent SAS from trying to execute the macro while CALL EXECUTE() is running and instead delay the macro processor from expanding the macro until it pulls the command back from the stack.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute ('%nrstr(%abc);') ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Aug 2018 14:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488889#M127502</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-22T14:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not refreshing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488910#M127512</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226448"&gt;@PJ007&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;%macro abc;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt;select max(anumber) into :maxnum&lt;BR /&gt;from&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;table1;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;%mend abc;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro import;&lt;/P&gt;
&lt;P&gt;%do I=1 %to &amp;amp;totobs. ;&lt;BR /&gt;data _null_;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;set&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;bcf_directory;&lt;BR /&gt;If obs=&amp;amp;i. ;&lt;/P&gt;
&lt;P&gt;IF filetype=".csv" THEN call execute ('%abc') ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%end;&lt;BR /&gt;%MEND Import;&lt;BR /&gt;%Import;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You might at least indicate where that "table1" data set is expected to change. You do not have anything here that reads or imports(possibly a poor choice for an automated process) a different data set. If you expect the macro %abc to get a different value then the actual table1 has to change. If there is actual import code you need to show where it might be in relationship to the call execute for %abc. There are possibly some timing problems with the stack of instructions call execute is generating. You might consider actually writing the program statements to a text file to examine if they are as expected. If the file looks good then %include that to run the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Very little code is so sensitive it can't be shared. Mask sensitive things like constants representing password, users, literal values but hiding actual program logic is not going to get answers directly to your problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 14:52:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488910#M127512</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-22T14:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not refreshing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488911#M127513</link>
      <description>&lt;P&gt;Thank you so so much! This worked!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 14:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-refreshing-values/m-p/488911#M127513</guid>
      <dc:creator>PJ007</dc:creator>
      <dc:date>2018-08-22T14:53:38Z</dc:date>
    </item>
  </channel>
</rss>

