<?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 Retrieve value from a macro variable to another macro variable uing a macro/loop in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Retrieve-value-from-a-macro-variable-to-another-macro-variable/m-p/336807#M22381</link>
    <description>&lt;P&gt;There are a bunch of global macro variables with assigned value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use a loop to do some stuff in a macro. At the beginning of the macro, will need to define a&amp;nbsp;new macro variable, and retrieve value from those global macro variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Period_1 = 11;
%let Period_2 = 22;
%let Period_3 = 33;
%global Period_temp;

%macro test;

%do _j=1 %to 3;

%let Period_temp = &amp;amp;&amp;amp;&amp;amp;(Period_&amp;amp;_j);           /* something might be wrong here */
...

	%end;
%mend test;
%test;

%PUT _ALL_;
run;

/* The log shows:

GLOBAL PERIOD_1 11
GLOBAL PERIOD_2 22
GLOBAL PERIOD_3 33
GLOBAL PERIOD_TEMP &amp;amp;(Period_3)          /* which is not 33 */

*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Clearly Period_temp is not picking up 'the numeric value', i.e. 11, 22, or 33.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How should I change the code?&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;What if I want Period_temp to be some calculation result involving Period_1,&amp;nbsp;&lt;SPAN&gt;Period_2,&amp;nbsp;Period_3?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;e.g. Period_temp = 11 + 22 * 33; How should I change the code?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Mar 2017 00:54:25 GMT</pubDate>
    <dc:creator>ayin</dc:creator>
    <dc:date>2017-03-01T00:54:25Z</dc:date>
    <item>
      <title>Retrieve value from a macro variable to another macro variable uing a macro/loop</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Retrieve-value-from-a-macro-variable-to-another-macro-variable/m-p/336807#M22381</link>
      <description>&lt;P&gt;There are a bunch of global macro variables with assigned value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use a loop to do some stuff in a macro. At the beginning of the macro, will need to define a&amp;nbsp;new macro variable, and retrieve value from those global macro variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Period_1 = 11;
%let Period_2 = 22;
%let Period_3 = 33;
%global Period_temp;

%macro test;

%do _j=1 %to 3;

%let Period_temp = &amp;amp;&amp;amp;&amp;amp;(Period_&amp;amp;_j);           /* something might be wrong here */
...

	%end;
%mend test;
%test;

%PUT _ALL_;
run;

/* The log shows:

GLOBAL PERIOD_1 11
GLOBAL PERIOD_2 22
GLOBAL PERIOD_3 33
GLOBAL PERIOD_TEMP &amp;amp;(Period_3)          /* which is not 33 */

*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Clearly Period_temp is not picking up 'the numeric value', i.e. 11, 22, or 33.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How should I change the code?&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;What if I want Period_temp to be some calculation result involving Period_1,&amp;nbsp;&lt;SPAN&gt;Period_2,&amp;nbsp;Period_3?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;e.g. Period_temp = 11 + 22 * 33; How should I change the code?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 00:54:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Retrieve-value-from-a-macro-variable-to-another-macro-variable/m-p/336807#M22381</guid>
      <dc:creator>ayin</dc:creator>
      <dc:date>2017-03-01T00:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve value from a macro variable to another macro variable uing a macro/loop</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Retrieve-value-from-a-macro-variable-to-another-macro-variable/m-p/336833#M22383</link>
      <description>&lt;P&gt;To retrieve a global variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let period_temp = &amp;amp;&amp;amp;period_&amp;amp;j;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The calculation you want isn't clear. &amp;nbsp;Did you really intend to apply both addition and multiplication?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming you want &amp;amp;PERIOD_TEMP to be 11, then 33, then 66 (the cumulative value of all the global variables so far), you could code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%global period_temp;&lt;/P&gt;
&lt;P&gt;%let period_temp=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then within the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let period_temp = %eval(&amp;amp;period_temp + &amp;amp;&amp;amp;period_&amp;amp;j);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you actually mean to use the formula you posted, you could simply code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let period_temp = %eval(&amp;amp;period_1 + &amp;amp;period_2 * &amp;amp;period_3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The %EVAL function is what forces macro language to perform the calculations.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 04:03:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Retrieve-value-from-a-macro-variable-to-another-macro-variable/m-p/336833#M22383</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-01T04:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve value from a macro variable to another macro variable uing a macro/loop</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Retrieve-value-from-a-macro-variable-to-another-macro-variable/m-p/336900#M22389</link>
      <description>&lt;P&gt;Why are you putting numeric "data" into text based macros? &amp;nbsp;It would benefit you far greater to put your period timepoint "data" in "datasets" - clue is in the name. &amp;nbsp;Then you can use merging (joining), lookups, datasteps and such like to work on the data. &amp;nbsp;Macro is a find/replace system, which modifies the actual text code sent to the compiler, it is not a data processing utility. &amp;nbsp;For instance, in a datastep you could do:&lt;/P&gt;
&lt;PRE&gt;data want;
  do i=11, 22, 33;
    put _all_;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Much simpler, easier to understand code.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 10:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Retrieve-value-from-a-macro-variable-to-another-macro-variable/m-p/336900#M22389</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-01T10:05:52Z</dc:date>
    </item>
  </channel>
</rss>

