<?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 LOOP question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335511#M75954</link>
    <description>hi I couldn't able to get the logic.&lt;BR /&gt;data new;&lt;BR /&gt;priciple=10000;&lt;BR /&gt;do i= 1 to 5;&lt;BR /&gt;retain priciple 0;&lt;BR /&gt;interest=(priciple*4)/100;&lt;BR /&gt;Amount=priciple+interest;&lt;BR /&gt;priciple=amount+interest&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;</description>
    <pubDate>Fri, 24 Feb 2017 06:03:32 GMT</pubDate>
    <dc:creator>tappu440</dc:creator>
    <dc:date>2017-02-24T06:03:32Z</dc:date>
    <item>
      <title>DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335508#M75952</link>
      <description>&lt;P class="p1"&gt;1.Write a SAS program to solve the given problem using Do&lt;/P&gt;&lt;P class="p4"&gt;Loop:&lt;/P&gt;&lt;P class="p4"&gt;A new account was opened in the SBI with initial deposit of&lt;/P&gt;&lt;P class="p4"&gt;Rs. 10,000/. SBI offers an interest rate of 4%. Find the balance&lt;/P&gt;&lt;P class="p4"&gt;after 5 years. Also store the every year and the balance.&lt;/P&gt;&lt;P class="p5"&gt;YEAR &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRINCIPAL &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;INTEREST &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AMOUNT&lt;/P&gt;&lt;P class="p6"&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10,000 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (P * R)/100 &amp;nbsp; &amp;nbsp; &amp;nbsp; A = P + INTEREST&lt;/P&gt;&lt;P class="p6"&gt;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; &amp;nbsp; P &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (P * R)/100 &amp;nbsp; &amp;nbsp; &amp;nbsp; A = A1 + INTEREST&lt;/P&gt;&lt;P class="p6"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p6"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p4"&gt;2. In the previous program what if the interest was paid&lt;/P&gt;&lt;P class="p4"&gt;quarterly.&lt;/P&gt;&lt;P class="p4"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p4"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p4"&gt;3. Calculate the amount for the following :&lt;/P&gt;&lt;P class="p4"&gt;Amount deposited = Rs. 5000/month.&lt;/P&gt;&lt;P class="p4"&gt;Rate of interest = 6 %&lt;/P&gt;&lt;P class="p4"&gt;Duration = 3 Years.&lt;/P&gt;&lt;P class="p4"&gt;Interest added yearly.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 05:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335508#M75952</guid>
      <dc:creator>tappu440</dc:creator>
      <dc:date>2017-02-24T05:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335509#M75953</link>
      <description>&lt;P&gt;Sorry, what's your question?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 05:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335509#M75953</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-24T05:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335511#M75954</link>
      <description>hi I couldn't able to get the logic.&lt;BR /&gt;data new;&lt;BR /&gt;priciple=10000;&lt;BR /&gt;do i= 1 to 5;&lt;BR /&gt;retain priciple 0;&lt;BR /&gt;interest=(priciple*4)/100;&lt;BR /&gt;Amount=priciple+interest;&lt;BR /&gt;priciple=amount+interest&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;</description>
      <pubDate>Fri, 24 Feb 2017 06:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335511#M75954</guid>
      <dc:creator>tappu440</dc:creator>
      <dc:date>2017-02-24T06:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335516#M75955</link>
      <description>&lt;P&gt;Read the log, and you'll find the error. It's THAT obvious, really.&lt;/P&gt;
&lt;P&gt;BTW your retain statement makes no sense. As your datastep only undergoes one iteration, it has no effect.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 07:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335516#M75955</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-24T07:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335517#M75956</link>
      <description>&lt;P&gt;RETIAN is used to save data in memory uninitialized at reading input.&lt;/P&gt;
&lt;P&gt;As you don't have input file nor sas dataset, you don't need use the retain.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your example is:&lt;/P&gt;
&lt;PRE&gt;YEAR  PRINCIPAL          INTEREST             AMOUNT
1     10,000            (P * R)/100       A = P + INTEREST
2       P               (P * R)/100       A = &lt;STRONG&gt;A1&lt;/STRONG&gt; + INTEREST
 &lt;/PRE&gt;
&lt;P&gt;in 2nd year you add interest to A1, no to A - so it should be comulative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
priciple=10000;  
Amount = priciple;  /* starting amount */
do i= 1 to 5;
     interest=priciple*4/100;   /* parenthesis not needed */
     Amount=priciple+interest;
     output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 07:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335517#M75956</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-24T07:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335519#M75957</link>
      <description>&lt;P&gt;Try this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
format priciple interest amount 20.2;
priciple = 10000;
do i = 1 to 5;
  interest = priciple * 4 / 100;
  amount = priciple + interest;
  priciple = amount + interest;
  output;
end;
run;

proc print data=new noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note how proper indentation and the use of spaces makes the code more readable&lt;/P&gt;
&lt;P&gt;Note the semicolon before the output statement (was missing in your code and causing an error)&lt;/P&gt;
&lt;P&gt;Note the omitted retain statement&lt;/P&gt;
&lt;P&gt;Note the use of a numeric format to make the results more readable&lt;/P&gt;
&lt;P&gt;The log:&lt;/P&gt;
&lt;PRE&gt;16         data new;
17         format priciple interest amount 20.2;
18         priciple = 10000;
19         do i = 1 to 5;
20           interest = (priciple * 4) / 100;
21           amount = priciple + interest;
22           priciple = amount + interest;
23           output;
24         end;
25         run;

NOTE: The data set WORK.NEW has 5 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.17 seconds
      cpu time            0.00 seconds
      

26         
27         proc print data=new noobs;
28         run;

NOTE: There were 5 observations read from the data set WORK.NEW.
NOTE: The PROCEDURE PRINT printed page 1.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.10 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;Clean and no extra NOTEs&lt;/P&gt;
&lt;P&gt;The result:&lt;/P&gt;
&lt;PRE&gt;priciple                interest                  amount    i

10800.00                  400.00                10400.00    1
11664.00                  432.00                11232.00    2
12597.12                  466.56                12130.56    3
13604.89                  503.88                13101.00    4
14693.28                  544.20                14149.09    5
&lt;/PRE&gt;
&lt;P&gt;You might consider dropping i from the dataset.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 07:48:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335519#M75957</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-24T07:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335521#M75958</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, are you not adding the interest twice:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  amount = priciple + interest;
  priciple = amount + interest;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should it not be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  amount = priciple + interest;
  priciple = amount;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Feb 2017 07:56:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335521#M75958</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-24T07:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335522#M75959</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, are you not adding the interest twice:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  amount = priciple + interest;
  priciple = amount + interest;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should it not be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  amount = priciple + interest;
  priciple = amount;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have to admit that I was not giving attention to the logic, just making the code syntactically correct and easy to read, as that was what caught my attention in the first place.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 08:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335522#M75959</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-24T08:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335524#M75960</link>
      <description>&lt;P&gt;May summarize up to now:&lt;/P&gt;
&lt;P&gt;1) I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;that identation is important in order that program will be more readable.&lt;/P&gt;
&lt;P&gt;2) According to example, one could think that interest is fixed, the same each year,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; than the code should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
priciple=10000;  
Amount = priciple;  /* starting amount */
do i= 1 to 5;
     interest=priciple*4/100;   /* parenthesis not needed */
     Amount=priciple+interest;
     output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In case, interset is to be calculated on comulative pricipe and yearly interests, than the code is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
priciple=10000;  
Amount = priciple;  /* starting amount */
do i= 1 to 5;
     interest=priciple*4/100;   /* parenthesis not needed */
     Amount=priciple+interest;
     output;
    &lt;STRONG&gt;pricipe = amount; &lt;/STRONG&gt;
end;
format pricipe amount interest comma8.2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Feb 2017 08:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335524#M75960</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-24T08:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335530#M75963</link>
      <description>&lt;P&gt;My preferred method for calculating amounts + interest is to use a simple multiplication, as that can be used to calculate a deliberately set number of years in one step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;amount = start * (1 + rate / 100) ** years;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Interest for a given year would then be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;interest = (start * (1 +  rate / 100) ** (years - 1)) * rate / 100;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code for the original problem would look like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
format priciple amount interest 20.2;
priciple = 10000;
rate = 4;
do years = 1 to 5;
  amount = priciple * (1 + rate / 100) ** years;
  interest = (priciple * (1 +  rate / 100) ** (years - 1)) * rate / 100;
  output;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The nice thing about this is that one does not have to run through all years starting with 1. One could run the calculations for years 20 to 25 only, and get the correct values.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 08:45:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335530#M75963</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-24T08:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335552#M75967</link>
      <description>excellent solutions, thanks for all</description>
      <pubDate>Fri, 24 Feb 2017 10:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335552#M75967</guid>
      <dc:creator>Yavuz</dc:creator>
      <dc:date>2017-02-24T10:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335604#M75990</link>
      <description>&lt;P&gt;This looks like a SAS class quiz/test problem&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 14:53:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335604#M75990</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-02-24T14:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335606#M75992</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/41810"&gt;@nehalsanghvi&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;This looks like a SAS class quiz/test problem&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A literal copy and paste of the assignment &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114436"&gt;@Yavuz&lt;/a&gt;&amp;nbsp;please mark one of the solutions provided as the correct answer&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 14:57:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335606#M75992</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-24T14:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335662#M76015</link>
      <description>Ok Reeza thank you for informing me.</description>
      <pubDate>Fri, 24 Feb 2017 16:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-question/m-p/335662#M76015</guid>
      <dc:creator>Yavuz</dc:creator>
      <dc:date>2017-02-24T16:58:51Z</dc:date>
    </item>
  </channel>
</rss>

