<?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: DO loops with regular monthly deposits and interest compounded annually, monthly and daily in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/601514#M173996</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/296186"&gt;@Magdalena56&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;You're headed in the right direction, just need to apply the correct expression. The COMPOUND function is called below just to compare the results with those generated by the canned SAS function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data annual ;                                                                                                                           
  retain principal 12000 rate 0.04 ;                                                                                                    
  do year = 1 to 5 ;                                                                                                                    
    earned = principal * (1 + rate) ** year ;                                                                                           
    comp = compound (principal, . , rate, year) ; *just for comparison ;                                                                
    output ;                                                                                                                            
  end ;                                                                                                                                 
run ;      
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Based on this template, you can surely generate the data sets for the monthly and daily periods yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Nov 2019 20:58:48 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2019-11-04T20:58:48Z</dc:date>
    <item>
      <title>DO loops with regular monthly deposits and interest compounded annually, monthly and daily</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/601494#M173988</link>
      <description>&lt;P&gt;I have been searching for an answer to this common exercise but could not find an example with &lt;STRONG&gt;regular monthly deposits&lt;/STRONG&gt; contributed over the investment period:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Savings account:&amp;nbsp;&lt;/P&gt;&lt;P&gt;$1000 contributed monthly for 5 years&lt;/P&gt;&lt;P&gt;1) Calculate savings after 5 years with interest=4% compounded annually (use DO loop)&lt;/P&gt;&lt;P&gt;2) Calculate savings after 5 years with interest=3.9% compounded monthly (use DO loop)&lt;/P&gt;&lt;P&gt;3) Calculate savings after 5 years with interest=3.8% compounded daily (use DO loop)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the codes I have tried (the third one seems to return unrealistic value):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data compound_annually;&lt;BR /&gt;principle=12000;&lt;BR /&gt;rate=0.04;&lt;BR /&gt;earned=0;&lt;BR /&gt;do year=1 to 5;&lt;BR /&gt;earned=principle+earned+(principle+earned)*rate;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data compound_monthly;&lt;BR /&gt;principle=1000;&lt;BR /&gt;rate=0.039/12;&lt;BR /&gt;earned=0;&lt;BR /&gt;do month=1 to 60;&lt;BR /&gt;earned=principle+earned+(principle+earned)*rate;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data compound_daily;&lt;BR /&gt;principle=32.87671233;&lt;BR /&gt;rate=0.038/4380;&lt;BR /&gt;earned=0;&lt;BR /&gt;do day=1 to 21900;&lt;BR /&gt;earned=principle+earned+(principle+earned)*rate;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please review the code and provide a better way to resolve the questions using do loops?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 20:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/601494#M173988</guid>
      <dc:creator>Magdalena56</dc:creator>
      <dc:date>2019-11-04T20:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: DO loops with regular monthly deposits and interest compounded annually, monthly and daily</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/601495#M173989</link>
      <description>&lt;P&gt;I'm surprised you want a DO loop solution. SAS has already done the hard work of creating functions for virtually any financial problem, then they have tested them and debugged them, so you don't have to. For example the FINANCE('FV',...) function seems to do what you want, with much less effort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0cv3zc7cq12jdn1mdvh9tzfzjdy.htm&amp;amp;locale=en"&gt;https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0cv3zc7cq12jdn1mdvh9tzfzjdy.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or at the very least, you can compare your do loops to the results of that function.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 20:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/601495#M173989</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-04T20:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: DO loops with regular monthly deposits and interest compounded annually, monthly and daily</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/601498#M173991</link>
      <description>&lt;P&gt;Thank you PaigeMiller! I agree financial functions are there for a reason &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; but the exercise requires do loops.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 20:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/601498#M173991</guid>
      <dc:creator>Magdalena56</dc:creator>
      <dc:date>2019-11-04T20:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: DO loops with regular monthly deposits and interest compounded annually, monthly and daily</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/601499#M173992</link>
      <description>&lt;P&gt;But you could see if you are getting the right answers from your do loops comparing to the FINANCE functions.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 20:16:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/601499#M173992</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-04T20:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: DO loops with regular monthly deposits and interest compounded annually, monthly and daily</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/601501#M173993</link>
      <description>Not getting the right answers except for #1.</description>
      <pubDate>Mon, 04 Nov 2019 20:22:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/601501#M173993</guid>
      <dc:creator>Magdalena56</dc:creator>
      <dc:date>2019-11-04T20:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: DO loops with regular monthly deposits and interest compounded annually, monthly and daily</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/601514#M173996</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/296186"&gt;@Magdalena56&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;You're headed in the right direction, just need to apply the correct expression. The COMPOUND function is called below just to compare the results with those generated by the canned SAS function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data annual ;                                                                                                                           
  retain principal 12000 rate 0.04 ;                                                                                                    
  do year = 1 to 5 ;                                                                                                                    
    earned = principal * (1 + rate) ** year ;                                                                                           
    comp = compound (principal, . , rate, year) ; *just for comparison ;                                                                
    output ;                                                                                                                            
  end ;                                                                                                                                 
run ;      
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Based on this template, you can surely generate the data sets for the monthly and daily periods yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 20:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/601514#M173996</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-11-04T20:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: DO loops with regular monthly deposits and interest compounded annually, monthly and daily</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/604734#M175348</link>
      <description>&lt;P&gt;Many thanks hashman, this is not correct though because neither the expression&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; earned &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; principal &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; rate&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;**&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;year&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;nor the compound function satisfy the condition that extra money is contributed every year (not just the initial amount compounded annually).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The expression "earned=principle+earned+(principle+earned)*rate;" yields a correct value, although not sure what financial function in SAS would be equivalent.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks again!&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2019 19:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-loops-with-regular-monthly-deposits-and-interest-compounded/m-p/604734#M175348</guid>
      <dc:creator>Magdalena56</dc:creator>
      <dc:date>2019-11-16T19:21:09Z</dc:date>
    </item>
  </channel>
</rss>

