<?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: I need help to calculate variable's value based on the previous value in the same variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/890110#M351709</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/446395"&gt;@IgorR&lt;/a&gt;&amp;nbsp;wrote:&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;If Year = 0 Then GrossFund = 0;&lt;BR /&gt;Else GrossFund = Lag(GrossFund)*(1+NGrossReturn) + &amp;amp;GrossAnnualPremium*(1-&amp;amp;ExpenceLoad)*(1+NGrossReturn);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This can not work. Since you do not call LAG when year is 0, the queue will still be empty when you call it when year is not 0, so you start the iterations with a missing value and proceed from there.&lt;/P&gt;
&lt;P&gt;Instead of using LAG, use RETAIN:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;retain GrossFund;
If Year = 0 Then GrossFund = 0;
Else GrossFund = GrossFund*(1+NGrossReturn) + &amp;amp;GrossAnnualPremium*(1-&amp;amp;ExpenceLoad)*(1+NGrossReturn);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 20 Aug 2023 16:36:34 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-08-20T16:36:34Z</dc:date>
    <item>
      <title>I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889473#M351436</link>
      <description>&lt;P&gt;I have excel table and my goal is to convert this table to SAS.&lt;/P&gt;&lt;P&gt;The table has almost 100 columns with different statistic formula in each column, when some formulas depend on other columns.&lt;/P&gt;&lt;P&gt;This is the small sample of the table:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; D&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; E&lt;/P&gt;&lt;P&gt;5&amp;nbsp; |Random number| Year | Normal Gross return | Gross Fund | Gross IRR |&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; | ------------------|------|-------------------------|--------------|------------|&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;6&amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;7&amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp;1.294000103 |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-18.13%&amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 76.96|&amp;nbsp; &amp;nbsp; &amp;nbsp;-18.13% |&lt;/DIV&gt;&lt;DIV&gt;8&amp;nbsp; |&amp;nbsp; &amp;nbsp;-0.330857931 |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 25.50%&amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 214.55|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9.14% |&lt;/DIV&gt;&lt;DIV&gt;9&amp;nbsp; |&amp;nbsp; -0.003978838 |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.55%&amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 334.92|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.85% |&lt;/DIV&gt;&lt;DIV&gt;10|&amp;nbsp; -0.130874637&amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4 |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -6.42%&amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 401.40|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2.63% |&lt;/DIV&gt;&lt;DIV&gt;11 | -0.508842621&amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.07%&amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 540.35|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4.69% |&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The excel formula to calculate column D (Gross Fund) is:&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;Cell(D7)=D6*(1+C7)+Premium*(1-expenseload)*(1+C7)&lt;/PRE&gt;Niotice, that in this column I have to take value from previous row.&lt;/DIV&gt;&lt;DIV&gt;"Premium" and "ExpenceLoad" are named ranges in excel.&lt;/DIV&gt;&lt;DIV&gt;I saw previous topics about Lag function and tried different approaches to solve the problem, but nothing gone well and I don't get the correct result.&lt;/DIV&gt;&lt;DIV&gt;The current SAS code in my program (Within Data step) is:&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;CODE class=""&gt;GrossFund = Lag(GrossFund)*(1+NGrossReturn)+&amp;amp;GrossAnnualPremium*(1-&amp;amp;ExpenceLoad)*(1+NGrossReturn);&lt;/CODE&gt;&lt;/PRE&gt;It returns Nulls only.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I need help to find the simplest solution to make the calculation with less steps as possible, because, as I noticed, i need to calculate almost a hundred additional variables. and i don't want the code to be to complicated and unreadable.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks in advance!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 09:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889473#M351436</guid>
      <dc:creator>IgorR</dc:creator>
      <dc:date>2023-08-16T09:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889474#M351437</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;DIV&gt;The excel formula to calculate column D (Gross Fund) is:&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;DIV&gt;
&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;Cell(D7)=D6*(1+C7)+Premium*(1-expenseload)*(1+C7)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since D6 is blank, I have no idea how the calculation works to give a value in D7. Please explain this.&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 16 Aug 2023 09:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889474#M351437</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-16T09:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889476#M351438</link>
      <description>Because of cell D6 in Excel is blank it's value in excel formula turns to be 0(zero).</description>
      <pubDate>Wed, 16 Aug 2023 09:36:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889476#M351438</guid>
      <dc:creator>IgorR</dc:creator>
      <dc:date>2023-08-16T09:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889480#M351440</link>
      <description>&lt;P&gt;Then you want to write code in SAS that says if any column D cell is missing, then you set it to zero.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 10:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889480#M351440</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-16T10:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889483#M351442</link>
      <description>&lt;P&gt;I tried this as well.&lt;/P&gt;&lt;P&gt;This is the code I tried:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;If Year = 0 Then GrossFund = 0;
GrossFund = Lag(GrossFund)*(1+NGrossReturn)+&amp;amp;GrossAnnualPremium*(1-&amp;amp;ExpenceLoad)*(1+NGrossReturn);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And this is result it return:&lt;/P&gt;&lt;PRE&gt;|&amp;nbsp; &amp;nbsp; 0|&amp;nbsp;  &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0|&amp;nbsp; &amp;nbsp; 0.00%&amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . |
|&amp;nbsp; &amp;nbsp; 1| 0.5126916173 | ( 18.13%) |&amp;nbsp; &amp;nbsp;76.95973857|
|&amp;nbsp; &amp;nbsp; 2| 0.9550716021 |&amp;nbsp; &amp;nbsp;25.50%&amp;nbsp; | &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .|
|&amp;nbsp; &amp;nbsp; 3| -0.875237107 |&amp;nbsp; &amp;nbsp; 8.55%&amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.|
|&amp;nbsp; &amp;nbsp; 4| 0.8329493204 | ( 6.42%)  | &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .|&lt;/PRE&gt;&lt;P&gt;As you can see this code works just once.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 10:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889483#M351442</guid>
      <dc:creator>IgorR</dc:creator>
      <dc:date>2023-08-16T10:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889484#M351443</link>
      <description>&lt;P&gt;Since you obviously have the data as a SAS data set, we need the SAS data set and not typed in Excel-clone data. Please provide the data as a working SAS data step code by following &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;. We don't need all 100 columns, just the relevant ones.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 13:00:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889484#M351443</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-16T13:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889514#M351464</link>
      <description>&lt;P&gt;Where do you set the value of the macro variables &amp;amp;grossannualpremium and &amp;amp;expenceload?&lt;/P&gt;
&lt;P&gt;Set to what?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there some grouping of data, such as client, company, fund or whatever?&lt;/P&gt;
&lt;P&gt;Is this use of LAG inside anything resembling an If/then/else block?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ENTIRE data step code, not snippets because other statements prior or after your shown statment(s) could quite easily effect the result.&lt;/P&gt;
&lt;P&gt;Example data in the form of a data step is a good idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that anyplace you use + if a term on either side is missing the result is missing&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 15:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889514#M351464</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-16T15:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889515#M351465</link>
      <description>&lt;P&gt;Does your log show the message&amp;nbsp;NOTE: Missing values were generated as a result of performing an operation on missing values?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 15:00:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889515#M351465</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-16T15:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889516#M351466</link>
      <description>&lt;P&gt;Looks to me like you are trying to BUILD data.&amp;nbsp; So you start with some initial values and that loop YEAR from 0 to whatever and apply the same formula over and over.&lt;/P&gt;
&lt;P&gt;So something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data initial_values;
  GrossFund = 1000;
  NGrossReturn = 0.10 ;
  GrossAnnualPremium = 200 ;
  ExpenceLoad = 0.25 ;
run;

data want;
  set initial_values;
  do year=0 to 10;
    output;
    GrossFund = GrossFund*(1+NGrossReturn)+GrossAnnualPremium*(1-ExpenceLoad)*(1+NGrossReturn);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;                             Gross
        Gross     NGross     Annual    Expence
Obs      Fund     Return    Premium      Load     year

  1    1000.00      0.1       200        0.25       0
  2    1265.00      0.1       200        0.25       1
  3    1556.50      0.1       200        0.25       2
  4    1877.15      0.1       200        0.25       3
  5    2229.87      0.1       200        0.25       4
  6    2617.85      0.1       200        0.25       5
  7    3044.64      0.1       200        0.25       6
  8    3514.10      0.1       200        0.25       7
  9    4030.51      0.1       200        0.25       8
 10    4598.56      0.1       200        0.25       9
 11    5223.42      0.1       200        0.25      10
&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Aug 2023 15:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889516#M351466</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-16T15:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889589#M351489</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Does your log show the message&amp;nbsp;NOTE: Missing values were generated as a result of performing an operation on missing values?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Yes. Here is the whole NOTE:&lt;/P&gt;&lt;PRE&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      2445000 at 65:36   2445000 at 65:47   2445000 at 65:62   3645000 at 72:27   105000 at 72:30    
NOTE: There were 3780000 observations read from the data set WORK.SIMULATOR1.
NOTE: The data set WORK.SIMULATOR_FINAL has 3780000 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           1.96 seconds
      cpu time            1.90 seconds&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 05:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889589#M351489</guid>
      <dc:creator>IgorR</dc:creator>
      <dc:date>2023-08-17T05:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889593#M351492</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Since you obviously have the data as a SAS data set, we need the SAS data set and not typed in Excel-clone data. Please provide the data as a working SAS data step code by following &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;. We don't need all 100 columns, just the relevant ones.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;The description is not so clear to me. Anyway, I prepared the code that build first 100 rows of the data set I'm working on.&lt;/P&gt;&lt;P&gt;To notice that the full set has:&lt;/P&gt;&lt;P&gt;6 Tranches (From 1 To 6),&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each tranche contains 15000 Iterations (From 1 to 15000),&lt;/P&gt;&lt;P&gt;Each Iteration contains 42 years (From 0 to 41) Where Rows with Year=0 must be blank or zero values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let Stdev_base = 0.187493224932249;
%let weight_to_equities = 0.5;
%let Stdev_ToUse = &amp;amp;Stdev_base*&amp;amp;weight_to_equities;
%let Term_Interval = 1;

Data Test;
Infile datalines dlm="09"x dsd;
Input Tranche Iteration Year NormInv  NetReturn Tresv NGrossReturn;
datalines;
1	1	0	0			0
1	1	1	-0.401683176	-0.192583212	16	-0.181279377
1	1	2	-2.188102767	0.237673136	16	0.25500056
1	1	3	-1.082351454	0.070470576	16	0.085457165
1	1	4	0.502844303	-0.077089014	16	-0.06416826
1	1	5	-0.764272142	0.075668747	16	0.09072811
1	1	6	0.832236652	0.080999439	16	0.096133431
1	1	7	-0.248428708	0.037800642	16	0.052329851
1	1	8	-0.696929109	0.012473564	16	0.026648194
1	1	9	-0.177708172	0.022553857	16	0.036869611
1	1	10	0.361635108	0.060861948	16	0.075714016
1	1	11	0.968456872	-0.03329219	16	-0.019758281
1	1	12	0.507503347	0.100902401	16	0.116315034
1	1	13	0.094918729	0.044654956	16	0.059280125
1	1	14	-0.268100788	0.100029068	16	0.115429475
1	1	15	1.114988618	-0.095820118	16	-0.0831616
1	1	16	0.621812038	0.020710059	16	0.035
1	1	17	-0.240327682			-0.03444714
1	1	18	-0.518506761			-0.05930167
1	1	19	-0.380628296			-0.047063621
1	1	20	0.216490394			0.007800988
1	1	21	-0.865064972			-0.08937257
1	1	22	0.516558723			0.036553334
1	1	23	0.635065672			0.048133258
1	1	24	0.614818545			0.046145683
1	1	25	1.703085114			0.15850912
1	1	26	0.306297412			0.016321587
1	1	27	1.054664304			0.090184211
1	1	28	-0.927067255			-0.094650243
1	1	29	-0.378329899			-0.046858273
1	1	30	1.37836213			0.123773543
1	1	31	0.698802551			0.054414724
1	1	32	1.877871249			0.177648372
1	1	33	-1.801178849			-0.165880781
1	1	34	-2.301837034			-0.204125642
1	1	35	-0.064140869			-0.01836675
1	1	36	-0.011118909			-0.013475268
1	1	37	0.16684725			0.003121704
1	1	38	-0.907010833			-0.092946383
1	1	39	-0.5522686			-0.062274328
1	1	40	-0.926762702			-0.094624394
1	1	41	-0.49304509			-0.057053593
1	2	0	0			0
1	2	1	0.272052109	-0.192583212	16	-0.181279377
1	2	2	-1.281898069	0.237673136	16	0.25500056
1	2	3	-0.647768883	0.070470576	16	0.085457165
1	2	4	-0.565498028	-0.077089014	16	-0.06416826
1	2	5	0.41197637	0.075668747	16	0.09072811
1	2	6	-0.779413048	0.080999439	16	0.096133431
1	2	7	0.855643268	0.037800642	16	0.052329851
1	2	8	-0.866463325	0.012473564	16	0.026648194
1	2	9	1.07588221	0.022553857	16	0.036869611
1	2	10	0.163612115	0.060861948	16	0.075714016
1	2	11	-0.033478564	-0.03329219	16	-0.019758281
1	2	12	-0.260679455	0.100902401	16	0.116315034
1	2	13	1.02590182	0.044654956	16	0.059280125
1	2	14	-2.021439569	0.100029068	16	0.115429475
1	2	15	-0.266694607	-0.095820118	16	-0.0831616
1	2	16	1.394018033	0.020710059	16	0.035
1	2	17	-0.042766779			-0.016397831
1	2	18	0.224547946			0.008562537
1	2	19	-2.84164275			-0.243398743
1	2	20	-0.529668341			-0.060285465
1	2	21	1.249656009			0.110295831
1	2	22	-0.032835878			-0.015481683
1	2	23	-0.336196189			-0.04308602
1	2	24	0.321693245			0.01778951
1	2	25	0.664098464			0.050989875
1	2	26	-0.969997516			-0.098286561
1	2	27	1.234485887			0.108717949
1	2	28	-0.371113375			-0.046213231
1	2	29	-0.217901648			-0.03241506
1	2	30	-0.487483006			-0.056561787
1	2	31	-0.462498733			-0.054349485
1	2	32	-0.425287629			-0.051044903
1	2	33	1.539378448			0.140865279
1	2	34	-0.458411447			-0.053987072
1	2	35	0.871198126			0.071594097
1	2	36	1.278369561			0.11328855
1	2	37	-0.232312352			-0.033721341
1	2	38	0.435834918			0.028738736
1	2	39	1.057741102			0.090498708
1	2	40	0.987034372			0.083294223
1	2	41	0.249422192			0.010917124
1	3	0	0			0
1	3	1	-0.24711478	-0.192583212	16	-0.181279377
1	3	2	0.193853784	0.237673136	16	0.25500056
1	3	3	0.722182005	0.070470576	16	0.085457165
1	3	4	-0.524994456	-0.077089014	16	-0.06416826
1	3	5	0.597940421	0.075668747	16	0.09072811
1	3	6	1.822602911	0.080999439	16	0.096133431
1	3	7	-0.66550602	0.037800642	16	0.052329851
1	3	8	0.229251942	0.012473564	16	0.026648194
1	3	9	0.515539259	0.022553857	16	0.036869611
1	3	10	-0.464778008	0.060861948	16	0.075714016
1	3	11	-2.071355087	-0.03329219	16	-0.019758281
1	3	12	-0.290791577	0.100902401	16	0.116315034
1	3	13	-0.092066762	0.044654956	16	0.059280125
1	3	14	0.564862272	0.100029068	16	0.115429475
1	3	15	-0.251988426	-0.095820118	16	-0.0831616
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Aug 2023 07:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889593#M351492</guid>
      <dc:creator>IgorR</dc:creator>
      <dc:date>2023-08-17T07:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889594#M351493</link>
      <description>&lt;P&gt;Hi Tom!&lt;/P&gt;&lt;P&gt;Please, see my reply to&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892" target="_blank"&gt;@PaigeMiller&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 07:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889594#M351493</guid>
      <dc:creator>IgorR</dc:creator>
      <dc:date>2023-08-17T07:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889690#M351529</link>
      <description>&lt;P&gt;I am starting to think that you have a misunderstanding of the LAG function.&lt;/P&gt;
&lt;P&gt;Your original post with&lt;/P&gt;
&lt;PRE&gt;GrossFund = Lag(GrossFund)*(1+NGrossReturn)+&amp;amp;GrossAnnualPremium*(1-&amp;amp;ExpenceLoad)*(1+NGrossReturn);&lt;/PRE&gt;
&lt;P&gt;(besides not showing any value for two macro variables) will not have a lagged value Grossfund if it does not exist in the input data set OR was not successfully assigned a value for Grossfund prior.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;data have;
   input x ;
datalines;
1 
2 
3 
;

data example;
   set have;
   y= lag(y)+x;
   z= sum( lag(z),x);
   q = lag(q) * x;
run;&lt;/PRE&gt;
&lt;P&gt;on the first iteration of the data step there are no lag values for any of y, z or q.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So on the first iteration y = &amp;lt;missing&amp;gt; + x. Which results in a missing value. That will be the lagged value of y in the next iteration.&lt;/P&gt;
&lt;P&gt;the SUM function however allows a result for missing plus actual values. So Z on the first step gets assigned a total of 1.&lt;/P&gt;
&lt;P&gt;Q is assigned the value of &amp;lt;missing&amp;gt; * x. Which is missing. That will be lagged value of Q.&lt;/P&gt;
&lt;P&gt;On the second iteration the lagged values of y and q are still missing. So result in missing values. And will continue to do so because the calculation used for those two variables in this example will always yield a missing result.&lt;/P&gt;
&lt;P&gt;Z however does accumulate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lets work through your GrossFund calculation. IF Grossfund does not have a value from another data step or previous assignment the first use is the Lag(grossfund) function. Returning missing. Multiply that by some value: result is missing. Add using + the result of another group of terms. The result is missing. So the Grossfund is assigned missing.&lt;/P&gt;
&lt;P&gt;Repeat the next time because no actual value other than missing was ever assigned to Grossfund.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the expectation for the FIRST execution of Grossfund is the part after the + sign the fix may be easy:&lt;/P&gt;
&lt;PRE&gt;GrossFund =Sum( Lag(GrossFund)*(1+NGrossReturn), &amp;amp;GrossAnnualPremium*(1-&amp;amp;ExpenceLoad)*(1+NGrossReturn)  );&lt;/PRE&gt;
&lt;P&gt;Maybe. Still may have issues depending what is actually in the 2 macro variables .&lt;/P&gt;
&lt;P&gt;If you do not want the First assignment to Grossfund to be&lt;/P&gt;
&lt;PRE&gt;&amp;amp;GrossAnnualPremium*(1-&amp;amp;ExpenceLoad)*(1+NGrossReturn)&lt;/PRE&gt;
&lt;P&gt;then more explanation is needed. And actual complete code used to "build" the data set. And the definitions of those macro variables.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 15:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889690#M351529</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-17T15:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889693#M351531</link>
      <description>&lt;P&gt;I don't understand.&lt;/P&gt;
&lt;P&gt;You seem to have all of the observations already in the source data.&lt;/P&gt;
&lt;P&gt;What are the variables where you already HAVE the data on the observation.&lt;/P&gt;
&lt;P&gt;What are the variables where you need to CREATE a value on the observation.&lt;/P&gt;
&lt;P&gt;What is the formula for creating the values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to GENERATE 6 'tranches'?&amp;nbsp; &amp;nbsp;Or do you already have them?&amp;nbsp; Could we just pull out the first observations per "tranch" from your giant file and have everything we need to create the other observations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 15:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889693#M351531</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-17T15:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889694#M351532</link>
      <description>&lt;P&gt;So if your input is this data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dsd dlm='|' truncover;
  input Tranche Iteration Year NormInv  NetReturn Tresv NGrossReturn;
datalines;
1|1|0|0|||0
1|1|1|-0.401683176|-0.192583212|16|-0.181279377
1|1|2|-2.188102767|0.237673136|16|0.25500056
1|1|3|-1.082351454| 0.070470576|16|0.085457165
1|1|4| 0.502844303|-0.077089014|16|-0.06416826
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is your OUTPUT.&amp;nbsp; Please share the desired output for this 6 observation input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Explain how you got from the INPUT to the OUTPUT.&lt;/P&gt;
&lt;P&gt;Do you want to add variables?&amp;nbsp; Which variables? How are they calculated?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to change the values of some variables? Which variables? On which observations?&lt;/P&gt;
&lt;P&gt;Do you want to add observations?&amp;nbsp; How many?&amp;nbsp; How is that determined?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 16:08:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/889694#M351532</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-17T16:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/890098#M351697</link>
      <description>&lt;P&gt;Ok, I will try to make a sense order.&lt;/P&gt;&lt;P&gt;I'm trying to build data set from scratch, when the goal is to make stochastic simulation of very large ammount of iteration and to get an average value from all results.&lt;/P&gt;&lt;P&gt;In the base of the calculation is random number that you can see in the first row of may data example.&lt;/P&gt;&lt;P&gt;The formula I provided suppose to calculate Variable with name "GrossFund" using additional, predefined parameters - in the table and macro vars.&lt;/P&gt;&lt;P&gt;I updated the code that bring to you the example data set.&lt;/P&gt;&lt;P&gt;And I added the excepted result for first 15 rows only because they must stay constant for each iteration and if I get the same results by the formula i suppose that formula works well.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 13:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/890098#M351697</guid>
      <dc:creator>IgorR</dc:creator>
      <dc:date>2023-08-20T13:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/890100#M351699</link>
      <description>&lt;P&gt;The Updated example code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let Stdev_base = 0.187493224932249;
%let weight_to_equities = 0.5;
%let Stdev_ToUse = &amp;amp;Stdev_base*&amp;amp;weight_to_equities;
%let Term_Interval = 1;
%let GrossAnnualPremium = 100;
%let ExpenceLoad = 0.06; 

Data Test;
Infile datalines dlm="09"x dsd;
Input Tranche Iteration Year NormInv  NetReturn Tresv NGrossReturn;

/*!!! Pidyon and Siluk - Check these parameters regularly to see
   if they has been changed!!!*/
datalines;
1	1	0	0			0
1	1	1	-0.401683176	-0.192583212	16	-0.181279377
1	1	2	-2.188102767	0.237673136	16	0.25500056
1	1	3	-1.082351454	0.070470576	16	0.085457165
1	1	4	0.502844303	-0.077089014	16	-0.06416826
1	1	5	-0.764272142	0.075668747	16	0.09072811
1	1	6	0.832236652	0.080999439	16	0.096133431
1	1	7	-0.248428708	0.037800642	16	0.052329851
1	1	8	-0.696929109	0.012473564	16	0.026648194
1	1	9	-0.177708172	0.022553857	16	0.036869611
1	1	10	0.361635108	0.060861948	16	0.075714016
1	1	11	0.968456872	-0.03329219	16	-0.019758281
1	1	12	0.507503347	0.100902401	16	0.116315034
1	1	13	0.094918729	0.044654956	16	0.059280125
1	1	14	-0.268100788	0.100029068	16	0.115429475
1	1	15	1.114988618	-0.095820118	16	-0.0831616
1	1	16	0.621812038	0.020710059	16	0.035
1	1	17	-0.240327682			-0.03444714
1	1	18	-0.518506761			-0.05930167
1	1	19	-0.380628296			-0.047063621
1	1	20	0.216490394			0.007800988
1	1	21	-0.865064972			-0.08937257
1	1	22	0.516558723			0.036553334
1	1	23	0.635065672			0.048133258
1	1	24	0.614818545			0.046145683
1	1	25	1.703085114			0.15850912
1	1	26	0.306297412			0.016321587
1	1	27	1.054664304			0.090184211
1	1	28	-0.927067255			-0.094650243
1	1	29	-0.378329899			-0.046858273
1	1	30	1.37836213			0.123773543
1	1	31	0.698802551			0.054414724
1	1	32	1.877871249			0.177648372
1	1	33	-1.801178849			-0.165880781
1	1	34	-2.301837034			-0.204125642
1	1	35	-0.064140869			-0.01836675
1	1	36	-0.011118909			-0.013475268
1	1	37	0.16684725			0.003121704
1	1	38	-0.907010833			-0.092946383
1	1	39	-0.5522686			-0.062274328
1	1	40	-0.926762702			-0.094624394
1	1	41	-0.49304509			-0.057053593
1	2	0	0			0
1	2	1	0.272052109	-0.192583212	16	-0.181279377
1	2	2	-1.281898069	0.237673136	16	0.25500056
1	2	3	-0.647768883	0.070470576	16	0.085457165
1	2	4	-0.565498028	-0.077089014	16	-0.06416826
1	2	5	0.41197637	0.075668747	16	0.09072811
1	2	6	-0.779413048	0.080999439	16	0.096133431
1	2	7	0.855643268	0.037800642	16	0.052329851
1	2	8	-0.866463325	0.012473564	16	0.026648194
1	2	9	1.07588221	0.022553857	16	0.036869611
1	2	10	0.163612115	0.060861948	16	0.075714016
1	2	11	-0.033478564	-0.03329219	16	-0.019758281
1	2	12	-0.260679455	0.100902401	16	0.116315034
1	2	13	1.02590182	0.044654956	16	0.059280125
1	2	14	-2.021439569	0.100029068	16	0.115429475
1	2	15	-0.266694607	-0.095820118	16	-0.0831616
1	2	16	1.394018033	0.020710059	16	0.035
1	2	17	-0.042766779			-0.016397831
1	2	18	0.224547946			0.008562537
1	2	19	-2.84164275			-0.243398743
1	2	20	-0.529668341			-0.060285465
1	2	21	1.249656009			0.110295831
1	2	22	-0.032835878			-0.015481683
1	2	23	-0.336196189			-0.04308602
1	2	24	0.321693245			0.01778951
1	2	25	0.664098464			0.050989875
1	2	26	-0.969997516			-0.098286561
1	2	27	1.234485887			0.108717949
1	2	28	-0.371113375			-0.046213231
1	2	29	-0.217901648			-0.03241506
1	2	30	-0.487483006			-0.056561787
1	2	31	-0.462498733			-0.054349485
1	2	32	-0.425287629			-0.051044903
1	2	33	1.539378448			0.140865279
1	2	34	-0.458411447			-0.053987072
1	2	35	0.871198126			0.071594097
1	2	36	1.278369561			0.11328855
1	2	37	-0.232312352			-0.033721341
1	2	38	0.435834918			0.028738736
1	2	39	1.057741102			0.090498708
1	2	40	0.987034372			0.083294223
1	2	41	0.249422192			0.010917124
1	3	0	0			0
1	3	1	-0.24711478	-0.192583212	16	-0.181279377
1	3	2	0.193853784	0.237673136	16	0.25500056
1	3	3	0.722182005	0.070470576	16	0.085457165
1	3	4	-0.524994456	-0.077089014	16	-0.06416826
1	3	5	0.597940421	0.075668747	16	0.09072811
1	3	6	1.822602911	0.080999439	16	0.096133431
1	3	7	-0.66550602	0.037800642	16	0.052329851
1	3	8	0.229251942	0.012473564	16	0.026648194
1	3	9	0.515539259	0.022553857	16	0.036869611
1	3	10	-0.464778008	0.060861948	16	0.075714016
1	3	11	-2.071355087	-0.03329219	16	-0.019758281
1	3	12	-0.290791577	0.100902401	16	0.116315034
1	3	13	-0.092066762	0.044654956	16	0.059280125
1	3	14	0.564862272	0.100029068	16	0.115429475
1	3	15	-0.251988426	-0.095820118	16	-0.0831616
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Aug 2023 13:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/890100#M351699</guid>
      <dc:creator>IgorR</dc:creator>
      <dc:date>2023-08-20T13:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/890101#M351700</link>
      <description>&lt;P&gt;Updated wanted result:&lt;/P&gt;&lt;PRE&gt;Random number	Year	Normal_Gross_return	Gross Fund
-0.049364577	1	-18.13%	                76.96
0.560315127	2	25.50%	                214.55
0.502450342	3	8.55%	                334.92
-0.061151989	4	-6.42%	                401.40
1.640308957	5	9.07%	                540.35
0.345543548	6	9.61%	                695.33
-0.953935106	7	5.23%	                830.63
0.53277643	8	2.66%	                949.27
-0.956756512	9	3.69%	                1081.74
0.598816648	10	7.57%	                1264.76
-0.321960944	11	-1.98%	                1331.91
1.057035832	12	11.63%	                1591.77
0.087963633	13	5.93%	                1785.70
-1.423907034	14	11.54%	                2096.67
0.450617369	15	-8.32%	                2008.49
-0.085762382	16	3.50%	                2176.08&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Aug 2023 13:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/890101#M351700</guid>
      <dc:creator>IgorR</dc:creator>
      <dc:date>2023-08-20T13:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/890106#M351705</link>
      <description>&lt;P&gt;You still seem to be missing a step in explaining what you are trying to do.&lt;/P&gt;
&lt;P&gt;But this is looking more and more like the goal is NOT to use LAG().&lt;/P&gt;
&lt;P&gt;The goal appears to be to generate (simulated) data.&amp;nbsp; So no need for LAG().&amp;nbsp; You don't need to LOOK UP some older values.&amp;nbsp; You just need to REMEMBER them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are getting closer to describing your inputs with this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Stdev_base = 0.187493224932249;
%let weight_to_equities = 0.5;
%let Stdev_ToUse = &amp;amp;Stdev_base*&amp;amp;weight_to_equities;
%let Term_Interval = 1;
%let GrossAnnualPremium = 100;
%let ExpenceLoad = 0.06; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So it looks like the first three macro variables will somehow be used in the generation of the simulated data. Are you assuming a NORMAL distribution when generating the data?&amp;nbsp; So you had SD , but what is the MEAN you want to use?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The 4th macro variable seems related to how many observations to generate?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The last two look like some of the inputs to the formula you started with for calculating the next value of GROSSFUND.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_GrossFund = GrossFund*(1+NGrossReturn)
              + &amp;amp;GrossAnnualPremium*(1-&amp;amp;ExpenceLoad)*(1+NGrossReturn)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you have not defined NGROSSRETURN.&lt;/P&gt;
&lt;P&gt;Is that another constant, like EXPENCELOAD?&lt;/P&gt;
&lt;P&gt;Is it the value that is going to be simulated using the value of&amp;nbsp;&lt;CODE class=" language-sas"&gt;Stdev_ToUse ?&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 14:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/890106#M351705</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-20T14:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: I need help to calculate variable's value based on the previous value in the same variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/890109#M351708</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;You still seem to be missing a step in explaining what you are trying to do.&lt;/P&gt;&lt;P&gt;But this is looking more and more like the goal is NOT to use LAG().&lt;/P&gt;&lt;P&gt;The goal appears to be to generate (simulated) data.&amp;nbsp; So no need for LAG().&amp;nbsp; You don't need to LOOK UP some older values.&amp;nbsp; You just need to REMEMBER them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are getting closer to describing your inputs with this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let Stdev_base = 0.187493224932249;
%let weight_to_equities = 0.5;
%let Stdev_ToUse = &amp;amp;Stdev_base*&amp;amp;weight_to_equities;
%let Term_Interval = 1;
%let GrossAnnualPremium = 100;
%let ExpenceLoad = 0.06; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So it looks like the first three macro variables will somehow be used in the generation of the simulated data. Are you assuming a NORMAL distribution when generating the data?&amp;nbsp; So you had SD , but what is the MEAN you want to use?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 4th macro variable seems related to how many observations to generate?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The last two look like some of the inputs to the formula you started with for calculating the next value of GROSSFUND.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;new_GrossFund = GrossFund*(1+NGrossReturn)
              + &amp;amp;GrossAnnualPremium*(1-&amp;amp;ExpenceLoad)*(1+NGrossReturn)
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But you have not defined NGROSSRETURN.&lt;/P&gt;&lt;P&gt;Is that another constant, like EXPENCELOAD?&lt;/P&gt;&lt;P&gt;Is it the value that is going to be simulated using the value of&amp;nbsp;&lt;CODE class=""&gt;Stdev_ToUse ?&lt;/CODE&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I need to calculate new variable - "GrossFund".&lt;/P&gt;&lt;P&gt;The formula to calculate "GrossFund" :&lt;/P&gt;&lt;PRE&gt;If Year = 0 Then GrossFund = 0;&lt;BR /&gt;Else GrossFund = Lag(GrossFund)*(1+NGrossReturn) + &amp;amp;GrossAnnualPremium*(1-&amp;amp;ExpenceLoad)*(1+NGrossReturn);&lt;/PRE&gt;&lt;P&gt;In Formula I use value from already existed column (Variable) - "&lt;CODE class=""&gt;NGrossReturn".&amp;nbsp;You&amp;nbsp;can&amp;nbsp;see&amp;nbsp;it&amp;nbsp;in&amp;nbsp;the&amp;nbsp;example&amp;nbsp;data&amp;nbsp;(the&amp;nbsp;code&amp;nbsp;to&amp;nbsp;get&amp;nbsp;the&amp;nbsp;example&amp;nbsp;i&amp;nbsp;posted&amp;nbsp;before).&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=""&gt;Also&amp;nbsp;I&amp;nbsp;use&amp;nbsp;two&amp;nbsp;constansts&amp;nbsp;-&amp;nbsp;&amp;amp;GrossAnnualPremium&amp;nbsp;and&amp;nbsp;&amp;amp;ExpenceLoad.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=""&gt;GrossFund&amp;nbsp;within&amp;nbsp;the&amp;nbsp;formula&amp;nbsp;must&amp;nbsp;be&amp;nbsp;previous&amp;nbsp;value&amp;nbsp;from&amp;nbsp;row&amp;nbsp;above&amp;nbsp;-&amp;nbsp;like&amp;nbsp;If&amp;nbsp;I&amp;nbsp;need&amp;nbsp;value&amp;nbsp;for&amp;nbsp;row&amp;nbsp;4&amp;nbsp;I&amp;nbsp;take&amp;nbsp;the&amp;nbsp;value&amp;nbsp;form&amp;nbsp;row&amp;nbsp;3&amp;nbsp;to&amp;nbsp;the&amp;nbsp;formula.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=""&gt;In&amp;nbsp;Addition,&amp;nbsp;I&amp;nbsp;have&amp;nbsp;in&amp;nbsp;the&amp;nbsp;data&amp;nbsp;variable&amp;nbsp;"Years".&amp;nbsp;It's&amp;nbsp;values&amp;nbsp;are&amp;nbsp;between&amp;nbsp;0&amp;nbsp;To&amp;nbsp;41,&amp;nbsp;Where&amp;nbsp;If&amp;nbsp;Year"&amp;nbsp;=&amp;nbsp;0&amp;nbsp;Then&amp;nbsp;GrossFund =&amp;nbsp;0;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=""&gt;When&amp;nbsp;I&amp;nbsp;run&amp;nbsp;the&amp;nbsp;code,&amp;nbsp;I&amp;nbsp;get&amp;nbsp;.&amp;nbsp;in&amp;nbsp;GrossFund&amp;nbsp;instead&amp;nbsp;of&amp;nbsp;numbers.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=""&gt;So,&amp;nbsp;I&amp;nbsp;undeerstand&amp;nbsp;that&amp;nbsp;I&amp;nbsp;use&amp;nbsp;Lag(GrossFund)&amp;nbsp;the&amp;nbsp;wrong&amp;nbsp;way,&amp;nbsp;but&amp;nbsp;I&amp;nbsp;can't&amp;nbsp;figure&amp;nbsp;it&amp;nbsp;out&amp;nbsp;what&amp;nbsp;to&amp;nbsp;do&amp;nbsp;to&amp;nbsp;get&amp;nbsp;values&amp;nbsp;in&amp;nbsp;the&amp;nbsp;formula,&amp;nbsp;not&amp;nbsp;"."&amp;nbsp;.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 15:59:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-help-to-calculate-variable-s-value-based-on-the-previous/m-p/890109#M351708</guid>
      <dc:creator>IgorR</dc:creator>
      <dc:date>2023-08-20T15:59:47Z</dc:date>
    </item>
  </channel>
</rss>

