<?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: How do I get each observation of a variable to move up by a percent of itself in the previous ob in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484794#M287067</link>
    <description>&lt;P&gt;This was completely correct.&amp;nbsp; I fixed the else statement and it worked exactly as I wanted it to.&amp;nbsp; Thank you for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Benefit_Amounts_PIA;
do year=2018 to 2050;
	PIA=1000;
	IF YEAR=2018 THEN COLA= .; ELSE COLA=.02;
if year=2018 then ADJ_PIA=PIA; 
	else adj_pia=ADJ_PIA*(1+COLA);

output;
end;
run'&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 07 Aug 2018 15:31:44 GMT</pubDate>
    <dc:creator>kharrigan</dc:creator>
    <dc:date>2018-08-07T15:31:44Z</dc:date>
    <item>
      <title>How do I get each observation of a variable to move up by a percent of itself in the previous observ</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484606#M287058</link>
      <description>&lt;P&gt;I want to create a data set that calculates a variable, ADJ_PIA, as PIA*(1+COLA) for observation 1.&amp;nbsp; Then, for subsequent observations, the calculation should be ADJ_PIA*(1+COLA).&amp;nbsp; Basically, each year the ADJ_PIA from the previous year should increase by the COLA percent.&amp;nbsp; The COLA is currently 2%, but could become variable later on.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is how the observations should look.&amp;nbsp; It represents a 2% increase over the previous value each time:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;YEAR&lt;/TD&gt;&lt;TD&gt;PIA&lt;/TD&gt;&lt;TD&gt;COLA&lt;/TD&gt;&lt;TD&gt;ADJ_PIA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2018&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;$1,000.00&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;$1,000.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2019&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;$1,000.00&lt;/TD&gt;&lt;TD&gt;2%&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;$1,020.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2020&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;$1,000.00&lt;/TD&gt;&lt;TD&gt;2%&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;$1,040.40&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2021&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;$1,000.00&lt;/TD&gt;&lt;TD&gt;2%&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;$1,061.21&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2022&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;$1,000.00&lt;/TD&gt;&lt;TD&gt;2%&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;$1,082.43&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;This is the first code I tried.&amp;nbsp; It's been pointed out that this is not valid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	if year=2018 then ADJ_PIA=PIA; 
	else ADJ_PIA*(1+COLA);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22284i4AB5DA0001DF5DB9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next code I tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ADJ_PIA=PIA*(1+COLA);
LAG_ADJ_PIA = LAG(ADJ_PIA);
ADJ_PIA2=LAG(ADJ_PIA)*(1+COLA);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This one doesn't have an error because it's valid.&amp;nbsp; It just isn't what I want to happen.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture2.PNG" style="width: 372px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22301iFBA74873438A7B56/image-dimensions/372x404?v=v2" width="372" height="404" role="button" title="Capture2.PNG" alt="Capture2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't even know how to search for what I want to do because I don't have a name for this process.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 15:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484606#M287058</guid>
      <dc:creator>kharrigan</dc:creator>
      <dc:date>2018-08-07T15:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get each observation of a variable to move up by a percent of itself in the previous ob</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484610#M287059</link>
      <description>&lt;P&gt;The statement you have after ELSE is not a valid SAS statement.&amp;nbsp; Don't you want an assignment statement there?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 04:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484610#M287059</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-07T04:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get each observation of a variable to move up by a percent of itself in the previous ob</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484612#M287060</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223328"&gt;@kharrigan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;I've attached an Excel sheet of what I'm trying to do because I cannot figure out how upload my actual SAS dataset, and honestly, it's a huge mess right now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why is it easier to type 20 numbers into a spreadsheet than to type them into a program? Or just into the forum.&amp;nbsp; Heck if you already have them in a spreadsheet then just copy and paste them into the forum editor.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 04:42:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484612#M287060</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-07T04:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get each observation of a variable to move up by a percent of itself in the previous ob</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484613#M287061</link>
      <description>&lt;P&gt;Avoid MS files please. Many people can't/won't download them.&lt;/P&gt;
&lt;P&gt;This method is the way to do what you want. Why won't you use it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;LAG_ADJ_PIA &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;LAG&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;ADJ_PIA&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
ADJ_PIA2&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;LAG_&lt;/SPAN&gt;ADJ_PIA&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;COLA&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 04:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484613#M287061</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-07T04:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get each observation of a variable to move up by a percent of itself in the previous ob</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484777#M287062</link>
      <description>&lt;P&gt;I will update my original question to be more clear without including an Excel file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't use it because it doesn't work.&amp;nbsp; This is the result I get when I run that code:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture2.PNG" style="width: 416px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22299i459BDA961636898E/image-dimensions/416x452?v=v2" width="416" height="452" role="button" title="Capture2.PNG" alt="Capture2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want one variable to calculate a 2% increase over the previous value.&amp;nbsp; So, for example, the observation values should be&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;$1,000.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;$1,020.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;$1,040.40&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;$1,061.21&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;$1,082.43&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This would show a 2% increase over the previous value each time.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 15:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484777#M287062</guid>
      <dc:creator>kharrigan</dc:creator>
      <dc:date>2018-08-07T15:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get each observation of a variable to move up by a percent of itself in the previous ob</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484780#M287063</link>
      <description>&lt;P&gt;I apologize.&amp;nbsp; I didn't realize I could just copy and paste from Excel into the text box.&amp;nbsp; I've updated my post.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 15:11:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484780#M287063</guid>
      <dc:creator>kharrigan</dc:creator>
      <dc:date>2018-08-07T15:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get each observation of a variable to move up by a percent of itself in the previous ob</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484782#M287064</link>
      <description>&lt;BLOCKQUOTE&gt;Don't you want an assignment statement there?&lt;/BLOCKQUOTE&gt;&lt;P&gt;I have not worked with assignment statements.&amp;nbsp; I will research and try this out.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 15:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484782#M287064</guid>
      <dc:creator>kharrigan</dc:creator>
      <dc:date>2018-08-07T15:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get each observation of a variable to move up by a percent of itself in the previous ob</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484784#M287065</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223328"&gt;@kharrigan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;Don't you want an assignment statement there?&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have not worked with assignment statements.&amp;nbsp; I will research and try this out.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your current THEN clause has a valid assignment statement.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 15:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484784#M287065</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-07T15:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get each observation of a variable to move up by a percent of itself in the previous ob</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484787#M287066</link>
      <description>&lt;P&gt;It is really not clear what data you are starting with.&lt;/P&gt;
&lt;P&gt;Let's assume you have this trivial dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  year=2018;
  pia=1000;
  cola=0.02 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if you want expand that to add 5 more years you could just run this simple data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
 set have ;
 output;
 do year=year+1 to year+5 ;
    pia = pia*(1+cola);
    output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;result&lt;/P&gt;
&lt;PRE&gt;Obs    year      pia      cola

 1     2018    1000.00    0.02
 2     2019    1020.00    0.02
 3     2020    1040.40    0.02
 4     2021    1061.21    0.02
 5     2022    1082.43    0.02
 6     2023    1104.08    0.02&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 15:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484787#M287066</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-07T15:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get each observation of a variable to move up by a percent of itself in the previous ob</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484794#M287067</link>
      <description>&lt;P&gt;This was completely correct.&amp;nbsp; I fixed the else statement and it worked exactly as I wanted it to.&amp;nbsp; Thank you for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Benefit_Amounts_PIA;
do year=2018 to 2050;
	PIA=1000;
	IF YEAR=2018 THEN COLA= .; ELSE COLA=.02;
if year=2018 then ADJ_PIA=PIA; 
	else adj_pia=ADJ_PIA*(1+COLA);

output;
end;
run'&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Aug 2018 15:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-each-observation-of-a-variable-to-move-up-by-a/m-p/484794#M287067</guid>
      <dc:creator>kharrigan</dc:creator>
      <dc:date>2018-08-07T15:31:44Z</dc:date>
    </item>
  </channel>
</rss>

