turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Use code to analyze return on investments

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-03-2014 04:09 PM

Hi guys,

If I place money in a fund that returns a compound interest of 4.25% annually. You

**deposit $1,000 every year**. How many years will it take to reach $30,000?

data bank;

deposit=1000;

do year=1 to 100 until (Total ge 30000);

** (Total+deposit)*1.0425; I want to add prior total with current year deposit and then multiple 1.0425.**

end; ** However the parentheses don't work here.**

run;

Accepted Solutions

Solution

09-03-2014
10:01 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-03-2014 10:01 PM

The SAVING function is for the simpler case where the compounding period is the same as the payment period. The period as the fourth argument is a missing value which signals to the SAVING function that the value to be returned is the number of periods. Any one of the arguments can be set to missing and the function will return its value from the other three (non missing).

For the *flexibility* that your example questions require, you are probably better off with 's approach.

PG

PG

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-03-2014 04:23 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-03-2014 04:53 PM

Thank you all the same.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-03-2014 04:29 PM

data bank;

do until (deposit ge 30000);

deposit + 1000;

deposit + deposit*0.0425;

year + 1;

output;

end;

run;

proc print data=bank noobs;

title 'years until atleast $30,000';

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-03-2014 05:07 PM

Thanks Hima!

What if I don't use Do loop to calculate it. Is there any compound function that I can use?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-03-2014 05:52 PM

You can use what Edward Ballard provided, its much better than what I provided and achieves what you are looking for in a simple function.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-03-2014 05:31 PM

You may not have all of the financial functions depending on your SAS Install but this may help.

This is simple annual interest.

data _null_;

rate = 0.0425;

years= saving(30000, 1000, rate, .);

put years= ;

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-03-2014 07:31 PM

Amazing solution!

By the way, what's the point within the parentheses for?

years= saving(30000, 1000, rate,** .**);

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-03-2014 08:05 PM

This solution is pretty smart.

However, I still couldn't apply this function flexibly even after reading SAS(R) 9.3 Functions and CALL Routines: Reference. I don't know the order of those arguments.

For example:

if I invest $1000 each year at the beginning, the rate is compounded quarterly, in which year and which quarter the balance will ge 30000?

if I invest $1000 each month for the first year, the rate is compounded quarterly, in which year and which quarter the balance will ge 30000?

if I invest $1000 each month for the first year, the rate is compounded monthly, in which year and which month the balance will ge 30000?

Thank you Ballard and look forward to your further help.

Solution

09-03-2014
10:01 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-03-2014 10:01 PM

The SAVING function is for the simpler case where the compounding period is the same as the payment period. The period as the fourth argument is a missing value which signals to the SAVING function that the value to be returned is the number of periods. Any one of the arguments can be set to missing and the function will return its value from the other three (non missing).

For the *flexibility* that your example questions require, you are probably better off with 's approach.

PG

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-03-2014 05:46 PM