<?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: Updating in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374454#M89666</link>
    <description>&lt;P&gt;i knew very well that the macro reference&amp;nbsp;were&amp;nbsp;resolved first.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much to all !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Jul 2017 11:56:36 GMT</pubDate>
    <dc:creator>DoumbiaS</dc:creator>
    <dc:date>2017-07-10T11:56:36Z</dc:date>
    <item>
      <title>Updating</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374405#M89643</link>
      <description>&lt;P&gt;Hey all,&lt;/P&gt;&lt;P&gt;Does someone see why my values don't update by each iteration i ?&lt;BR /&gt;I want values update in each iteration i and throughout my statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data need;
	do i= 1 to 5;
		min= 1; max= 10; val_m1= 5; val_m2= 7;
		m1= 3;
		m2= 5;
		min= m1; m1= m2;	 		            /*here 2 updates*/
 		val_m1= val_m2;  		                    /*update*/
		m2= (m2 + max) / 2; 		            /*update*/
		call execute('%mymacro('||m2||')'); 
 /*These macro have to use the last m2 update value */
		val_m2= &amp;amp;val_m2; 	
 /*A global macro var named val_m2 is created in %mymacro*/
	
       output;
       end;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mymacro like this one:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro mymacro (m2);
   %glabal val_m2;                      /*name can be changed if optimal*/
   ...
   ...
%mend;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 09:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374405#M89643</guid>
      <dc:creator>DoumbiaS</dc:creator>
      <dc:date>2017-07-10T09:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: Updating</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374409#M89644</link>
      <description>&lt;P&gt;In this line&lt;/P&gt;
&lt;PRE&gt;val_m2= &amp;amp;val_m2;&lt;/PRE&gt;
&lt;P&gt;the macro variable &amp;amp;val_m2 is resolved by the macro &lt;U&gt;&lt;STRONG&gt;PRE&lt;/STRONG&gt;&lt;/U&gt;processor before the data step is compiled and run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I strongly suggest that you pack the logic contained in the macro in a user defined function, or rewrite the macro so that you can use it to create standard code for use in the data step itself (without call execute).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For further help, post the code of your macro %mymacro.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 09:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374409#M89644</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-10T09:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: Updating</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374417#M89645</link>
      <description>&lt;P&gt;" the macro variable &amp;amp;val_m2 is resolved by the macro &lt;U&gt;&lt;STRONG&gt;PRE&lt;/STRONG&gt;&lt;/U&gt;processor before the data step is compiled and run "&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You 're right, thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But i reformulated the problem for simplicity.&lt;/P&gt;&lt;PRE&gt;%macro mymacro(var);
%Global used;
	%let used= %sysevalf(&amp;amp;var +1);
%Mend;

data need;
do i= 1 to 3;
	if i= 1 then do;
		x= 2;
		y= 3;
		call execute('%mymacro('||x||')');
		val2= &amp;amp;used;           
	end;
	else do;
		x= x+2;
		y= (y+2)/2;
		call execute('%mymacro('||x||')');
		val2= &amp;amp;used;
	end;
output;
end;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; i     x    y         val2

1    2    3          3
2    4    2.5       5
3    6    2.25     7&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Jul 2017 10:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374417#M89645</guid>
      <dc:creator>DoumbiaS</dc:creator>
      <dc:date>2017-07-10T10:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Updating</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374430#M89652</link>
      <description>&lt;P&gt;Kurt mentioned the right principle ... there is absolutely nothing about your code that changes &amp;amp;USED within this statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;val2 = &amp;amp;used;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its value gets changed by this code, but the statements within the DATA step depend on the initial value of &amp;amp;USED before the DATA step begins. &amp;nbsp;You could work around this by replacing that statement with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;val2 = input(symget('used'), 12.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested but worth a try with one just one precaution. &amp;nbsp;I hope this is just a test to see how macro language works. &amp;nbsp;If this were a real application, there would likely be many better ways to handle the situation.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 10:37:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374430#M89652</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-10T10:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: Updating</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374433#M89654</link>
      <description>&lt;P&gt;Still the same mistake. &amp;amp;used will be resolved&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;BEFORE!!&lt;/STRONG&gt;&lt;/U&gt; the macro calls from the call execute will create the macro variable.&lt;/P&gt;
&lt;P&gt;If you just want to build an increment, macro programming is NOT NEEDED AT ALL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 10:42:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374433#M89654</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-10T10:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: Updating</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374454#M89666</link>
      <description>&lt;P&gt;i knew very well that the macro reference&amp;nbsp;were&amp;nbsp;resolved first.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much to all !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 11:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374454#M89666</guid>
      <dc:creator>DoumbiaS</dc:creator>
      <dc:date>2017-07-10T11:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: Updating</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374530#M89697</link>
      <description>&lt;P&gt;What about te informat 12. applied to the numeric variable val2 ?&lt;/P&gt;&lt;P&gt;Could the number of digit in my global macro var used be an issue ?&lt;/P&gt;&lt;P&gt;Such it doesn't work with my initial data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 14:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374530#M89697</guid>
      <dc:creator>DoumbiaS</dc:creator>
      <dc:date>2017-07-10T14:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Updating</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374538#M89701</link>
      <description>&lt;P&gt;For example this one fails&amp;nbsp;do execute:&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need4;
do i= 1 to 3;
	if i= 1 then do;
		x= 22222222222;
		y= 33333333333;
		val_x= 11111111111;
		call execute('%mymacro('||x||')');
		val_y = input(symget('used'), 12.); 
	end;
	else do;
		x= x+2;
		y= (y+2)/2;
		val_x= val_y; 
		call execute('%mymacro('||x||')');
		val_y = input(symget('used'), 12.);
	end;
output;
end;
run;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Jul 2017 14:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374538#M89701</guid>
      <dc:creator>DoumbiaS</dc:creator>
      <dc:date>2017-07-10T14:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Updating</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374547#M89702</link>
      <description>&lt;P&gt;When I run your code, it works.&amp;nbsp; What failed to execute?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, the informat could be a problem.&amp;nbsp; But not for 11-digit integers.&amp;nbsp; There might be an issue with different formulas if they generate decimal fractions.&amp;nbsp; But the code that you posted should run without incident.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 15:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374547#M89702</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-10T15:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: Updating</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374558#M89704</link>
      <description>&lt;P&gt;True. It may be because of my own operations.&lt;BR /&gt;Also, in my elso do: call execute don't use my last x value. Any thoughts ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 15:17:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374558#M89704</guid>
      <dc:creator>DoumbiaS</dc:creator>
      <dc:date>2017-07-10T15:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Updating</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374580#M89713</link>
      <description>&lt;P&gt;Here are the results I got:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Obs i &amp;nbsp;x&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val_x&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val_y&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;　&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1&amp;nbsp; &amp;nbsp;1&amp;nbsp; 22222222222 33333333333.0 11111111111 22222222223&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp; &amp;nbsp;2&amp;nbsp; 22222222224 16666666667.5 22222222223 22222222225&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;3&amp;nbsp;&amp;nbsp; 3&amp;nbsp; 22222222226 8333333334.8&amp;nbsp; 22222222225 22222222227&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;Did you get the same?&amp;nbsp; The results are short enough that you should be able to post them and explain how they are different than what you expect.&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>Mon, 10 Jul 2017 16:11:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374580#M89713</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-10T16:11:04Z</dc:date>
    </item>
    <item>
      <title>Re: Updating</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374829#M89799</link>
      <description>&lt;P&gt;True. My problem is from my original own macro i think.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 08:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating/m-p/374829#M89799</guid>
      <dc:creator>DoumbiaS</dc:creator>
      <dc:date>2017-07-11T08:05:24Z</dc:date>
    </item>
  </channel>
</rss>

