<?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: Rolling forward calculations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rolling-forward-calculations/m-p/291554#M60406</link>
    <description>&lt;P&gt;A good example of 'RETAIN';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
retain y;
if _n_ ne 1 then x=y;
y=x*a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 14 Aug 2016 01:39:27 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2016-08-14T01:39:27Z</dc:date>
    <item>
      <title>Rolling forward calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-forward-calculations/m-p/291513#M60400</link>
      <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would be glad, if you could help me with the following problem.&lt;/P&gt;&lt;P&gt;What I am aiming at implementing is the following:&lt;/P&gt;&lt;P&gt;In the &lt;U&gt;first row&lt;/U&gt;, I calculate a specific variable, e.g., y = x*a;&lt;/P&gt;&lt;P&gt;Said y shall be carried forward to the &lt;U&gt;second row&lt;/U&gt; a play the role as the new x. The same calculation is performed, i.e., y=x*a, whereby the x for the second row is the y from the first row;&lt;/P&gt;&lt;P&gt;That is the input&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/4590iEC3C83FBBF1D3849/image-size/original?v=v2&amp;amp;px=-1" alt="have.JPG" title="have.JPG" border="0" /&gt;&lt;/P&gt;&lt;P&gt;and output&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/4591iE1A4741C9B01B974/image-size/original?v=v2&amp;amp;px=-1" alt="want.JPG" title="want.JPG" border="0" /&gt;&lt;/P&gt;&lt;P&gt;I am considering.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be kind, if you could give me a hint, on how to I tackle this kind of problem?&lt;/P&gt;&lt;P&gt;As SAS "work" row to row (as I have understood), it should give a "trick"?&lt;/P&gt;&lt;P&gt;Otherwise, for each step, I would have to create an index, separate the y, merge the y to the next observation, replace x with the carried-forward-y and calculate once again.&lt;/P&gt;&lt;P&gt;This would result in a huge amount of data steps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input x a;
  datalines;
1	2
.	2
.	2
.	2
.	2
.	2
.	2
.	2
.	2
.	2
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Aug 2016 10:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-forward-calculations/m-p/291513#M60400</guid>
      <dc:creator>Sinistrum</dc:creator>
      <dc:date>2016-08-13T10:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling forward calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-forward-calculations/m-p/291515#M60401</link>
      <description>&lt;P&gt;Here is a way by data step. Replace x by everytime before the next iteration like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
a = 2;
do i = 1 to 10;
   if i = 1 then x = 1;
   y = x * a;

   output;
   x = y;
end;
drop i;
run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hope this is an acceptable solution to you.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Aug 2016 11:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-forward-calculations/m-p/291515#M60401</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-08-13T11:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling forward calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-forward-calculations/m-p/291554#M60406</link>
      <description>&lt;P&gt;A good example of 'RETAIN';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
retain y;
if _n_ ne 1 then x=y;
y=x*a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Aug 2016 01:39:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-forward-calculations/m-p/291554#M60406</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-08-14T01:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling forward calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-forward-calculations/m-p/291583#M60416</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is enormous.&lt;/P&gt;&lt;P&gt;I really had allready implemented it via a %macro %Do Loop.&lt;/P&gt;&lt;P&gt;The amount of time if do save is astonishing.&lt;/P&gt;&lt;P&gt;Thank you so much for this - I need this very procedure "over an over" so this really changes the game.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I do have to implement it for more than one variable, would you mind considering if I have transferred it correctly to a setting more closely to the actual one?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

retain x_end y_end z_end;

if _n_ ne 1 then x=x_end;
if _n_ ne 1 then y=y_end;
if _n_ ne 1 then z=z_end;

x_end		=		intercept1		

						+		a*x
						+		b*y
						+		c*z
;

y_end		=		intercept2

						+		d*x
						+		e*y
						+		f*z

;

z_end		=		intercept3

						+		g*x
						+		h*y
						+		i*z
;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So, former y is now "x_end";&lt;/P&gt;&lt;P&gt;Especially, the three ifs are a concern of mine - could I achieve a better solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, nonetheless, your very answer means a huge leap indeed for me.&lt;/P&gt;&lt;P&gt;Once again, thank you so much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Aug 2016 13:04:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-forward-calculations/m-p/291583#M60416</guid>
      <dc:creator>Sinistrum</dc:creator>
      <dc:date>2016-08-14T13:04:06Z</dc:date>
    </item>
  </channel>
</rss>

