<?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 Recursive calculations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Recursive-calculations/m-p/634407#M188280</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to recursively estimate some indicator according to the formula:&lt;/P&gt;
&lt;P&gt;indicator_t=0.93*indicator_t-1 + 0.07(series1-0,5)*(series2-0.5)&lt;/P&gt;
&lt;P&gt;I run a following code. It produces the results. However, when I export the data to Excel and run calculations manually for period=2, I get different results (see the attached pdf with a print screen). What is wrong with the code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input period x1 x2 x3;
	datalines;
	1	0.509181970	0.449638286 0.023773669827945
	2	0.600445186	0.623260991 .
	3	0.674457429	0.526989427 .
	4	0.433500278	0.563717307 .
	5	0.503060657	0.514746800 .
	;
run;
data have;
	set have;
	lag_x3=lag(x3);
run;

%macro loop;
	%do i=2 %to 5 /*&amp;amp;nobs*/;
		data have;
			set have;
			if period=&amp;amp;i then do;
				x3=0.93*lag_x3 + 0.07*(x1-0.5)*(x2-0.05);				
			end;
			lag_x3=lag(x3);
		run;
	%end;
%mend;
%loop;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 24 Mar 2020 12:25:41 GMT</pubDate>
    <dc:creator>chris2377</dc:creator>
    <dc:date>2020-03-24T12:25:41Z</dc:date>
    <item>
      <title>Recursive calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursive-calculations/m-p/634407#M188280</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to recursively estimate some indicator according to the formula:&lt;/P&gt;
&lt;P&gt;indicator_t=0.93*indicator_t-1 + 0.07(series1-0,5)*(series2-0.5)&lt;/P&gt;
&lt;P&gt;I run a following code. It produces the results. However, when I export the data to Excel and run calculations manually for period=2, I get different results (see the attached pdf with a print screen). What is wrong with the code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input period x1 x2 x3;
	datalines;
	1	0.509181970	0.449638286 0.023773669827945
	2	0.600445186	0.623260991 .
	3	0.674457429	0.526989427 .
	4	0.433500278	0.563717307 .
	5	0.503060657	0.514746800 .
	;
run;
data have;
	set have;
	lag_x3=lag(x3);
run;

%macro loop;
	%do i=2 %to 5 /*&amp;amp;nobs*/;
		data have;
			set have;
			if period=&amp;amp;i then do;
				x3=0.93*lag_x3 + 0.07*(x1-0.5)*(x2-0.05);				
			end;
			lag_x3=lag(x3);
		run;
	%end;
%mend;
%loop;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Mar 2020 12:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursive-calculations/m-p/634407#M188280</guid>
      <dc:creator>chris2377</dc:creator>
      <dc:date>2020-03-24T12:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursive-calculations/m-p/634410#M188281</link>
      <description>I've made a mistake in the code (x2-0.05) instead (x2-0.5). It's all OK now. Please disregard the post. Sorry for the mess</description>
      <pubDate>Tue, 24 Mar 2020 12:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursive-calculations/m-p/634410#M188281</guid>
      <dc:creator>chris2377</dc:creator>
      <dc:date>2020-03-24T12:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursive-calculations/m-p/634414#M188284</link>
      <description>&lt;P&gt;Please copy/paste your "have" data step from here and try to run it. You will find that it does not work, as somewhere there were tabs introduced.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you do it so complicated in SAS? If all you want is to calculate x3, this is the code to do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input period x1 x2 x3;
datalines;
1 0.509181970 0.449638286 0.023773669827945
2 0.600445186 0.623260991 .
3 0.674457429 0.526989427 .
4 0.433500278 0.563717307 .
5 0.503060657 0.514746800 .
;

data want;
set have;
retain lag_x3;
if _n_ = 1 then lag_x3 = x3;
else do;
  x3=0.93*lag_x3 + 0.07*(x1-0.5)*(x2-0.05);
  lag_x3 = x3;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Mar 2020 12:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursive-calculations/m-p/634414#M188284</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-24T12:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursive-calculations/m-p/634420#M188288</link>
      <description>&lt;P&gt;Or (similar to Kurt Bremser's code):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
retain lag_x3;
if period&amp;gt;1 then x3=0.93*lag_x3+0.07*(x1-0.5)*(x2-0.5);
output;
lag_x3=x3;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Mar 2020 13:04:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursive-calculations/m-p/634420#M188288</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-03-24T13:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: Recursive calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recursive-calculations/m-p/634427#M188295</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I haven't thought of doing this differently. The first thing that came to my mind was using macro. Apparently, there's easier way. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 13:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recursive-calculations/m-p/634427#M188295</guid>
      <dc:creator>chris2377</dc:creator>
      <dc:date>2020-03-24T13:51:30Z</dc:date>
    </item>
  </channel>
</rss>

