<?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 Macro variable in the loop; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-the-loop/m-p/378278#M90866</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;I have unexpected result from the call symput function of SAS.&lt;BR /&gt;&lt;BR /&gt;I wrote this code:&lt;/P&gt;
&lt;PRE&gt;data tab1;
	a=1; b=2; output;
	a=3; b=5; output;
run;

%macro loop;
	data tab2;
		set tab1;
		%do i=1 %to 2;
			call symput(cats('var',&amp;amp;i),a);
			call symput(cats('dem',&amp;amp;i),b);
		%end;
	run;

	%do i=1 %to 2;
		%put i &amp;amp;&amp;amp;var&amp;amp;i &amp;amp;&amp;amp;dem&amp;amp;i;
	%end;
%mend;

%loop;&lt;/PRE&gt;
&lt;P&gt;from this code I get the result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 3 5&lt;BR /&gt;2 3 5&lt;BR /&gt;&lt;BR /&gt;Instead of :&lt;/P&gt;
&lt;P&gt;1 1 2&lt;/P&gt;
&lt;P&gt;2 3 5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(In linux...sas doesn't recognize the macro variable &amp;amp;&amp;amp;var&amp;amp;i ).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't understand why... I need to save some variable in the macro variable... some of you has some solution and explain why I get this result? really..I can't understand..&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jul 2017 19:25:48 GMT</pubDate>
    <dc:creator>Rakeon</dc:creator>
    <dc:date>2017-07-21T19:25:48Z</dc:date>
    <item>
      <title>Macro variable in the loop;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-the-loop/m-p/378278#M90866</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I have unexpected result from the call symput function of SAS.&lt;BR /&gt;&lt;BR /&gt;I wrote this code:&lt;/P&gt;
&lt;PRE&gt;data tab1;
	a=1; b=2; output;
	a=3; b=5; output;
run;

%macro loop;
	data tab2;
		set tab1;
		%do i=1 %to 2;
			call symput(cats('var',&amp;amp;i),a);
			call symput(cats('dem',&amp;amp;i),b);
		%end;
	run;

	%do i=1 %to 2;
		%put i &amp;amp;&amp;amp;var&amp;amp;i &amp;amp;&amp;amp;dem&amp;amp;i;
	%end;
%mend;

%loop;&lt;/PRE&gt;
&lt;P&gt;from this code I get the result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 3 5&lt;BR /&gt;2 3 5&lt;BR /&gt;&lt;BR /&gt;Instead of :&lt;/P&gt;
&lt;P&gt;1 1 2&lt;/P&gt;
&lt;P&gt;2 3 5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(In linux...sas doesn't recognize the macro variable &amp;amp;&amp;amp;var&amp;amp;i ).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't understand why... I need to save some variable in the macro variable... some of you has some solution and explain why I get this result? really..I can't understand..&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2017 19:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-the-loop/m-p/378278#M90866</guid>
      <dc:creator>Rakeon</dc:creator>
      <dc:date>2017-07-21T19:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable in the loop;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-the-loop/m-p/378281#M90868</link>
      <description>&lt;P&gt;The statements execute in a different order than you are expecting. &amp;nbsp;Your code adds four statements to the DATA step, creating:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data tab2;&lt;/P&gt;
&lt;P&gt;set tab1;&lt;/P&gt;
&lt;P&gt;call symput(cats('var',1), a);&lt;/P&gt;
&lt;P&gt;call symput(cats('dem',1),b);&lt;/P&gt;
&lt;P&gt;call symput(cats('var',2),a);&lt;/P&gt;
&lt;P&gt;call symput(cats('dem',2),b);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All of that occurs before the DATA step begins to run. &amp;nbsp;Once all the statements are complete, the DATA step executes. &amp;nbsp;So for the first observation from TAB1, all four statements execute. &amp;nbsp;Then for the second observation from TAB1, all four statements execute, replacing the values assigned previously.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2017 19:33:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-the-loop/m-p/378281#M90868</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-21T19:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable in the loop;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-the-loop/m-p/378287#M90870</link>
      <description>&lt;P&gt;Thanks Astounding,&lt;BR /&gt;Your answer is very clear!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;but.. if i want to save some variable of data set in the macro, what should i do?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;because i haven't any idea...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2017 19:49:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-the-loop/m-p/378287#M90870</guid>
      <dc:creator>Rakeon</dc:creator>
      <dc:date>2017-07-21T19:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable in the loop;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-the-loop/m-p/378294#M90871</link>
      <description>&lt;P&gt;There's always a way. &amp;nbsp;Here's one idea:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data tab2;&lt;/P&gt;
&lt;P&gt;set tab1;&lt;/P&gt;
&lt;P&gt;call symput(cats('var',_n_), a);&lt;/P&gt;
&lt;P&gt;call symput(cats('dem',_n_),b);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2017 20:08:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-the-loop/m-p/378294#M90871</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-21T20:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable in the loop;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-the-loop/m-p/378299#M90873</link>
      <description>&lt;P&gt;Wow!!&lt;BR /&gt;&lt;BR /&gt;Thanks Astounding!!!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2017 20:12:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-in-the-loop/m-p/378299#M90873</guid>
      <dc:creator>Rakeon</dc:creator>
      <dc:date>2017-07-21T20:12:02Z</dc:date>
    </item>
  </channel>
</rss>

