- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone, please I need clarification with these programs. What is each program is trying to calculate? Each program gives different output. I do not get the logic that differentiate the different methods.
data work.earn;
capital=2000;
do month=1 to 12;
Interest=capital*.075;
capital+interest;
output;
end;
run;
data work.earn;
Capital=2000;
do month=1 to 12;
Interest=capital*(.075/12);
capital+interest;
output;
end;
run;
data work.earn;
Capital=2000;
do month=1 to 12;
Interest=capital*(.075/12);
earned+capital+interest;
output;
end;
run;
data work.earn;
capital=2000;
rate = .075/12;
do month=1 to 12;
Earned+(capital+earned)*rate;
output;
end;
run;
Thank you.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@PrinceAde wrote:
Hi @Patrick , this is very helpful, thank you.
I have one last clarification to make, please.
If the question says $2000 is invested each year, does that not mean that the value of PV should increment by 2000 for the three years 2000, 4000, and 6000, rather than remain 2000?
True! And a good example that one always needs to verify answers provided by chatGPT.
And it also makes me think that eventually one intention of your exercises is to make you realize that you've got two approaches for solving such problems:
The smart way where you work out the proper formula (function) for the problem that allows you to directly retrieve the value after n-years or the dumber approach where you make the computer iterate over a function that only works for a single year.
There are also some SAS functions for available for financial calculations and it might be worth for you to consult the SAS docu.
Below an example for the dumber approach.
data work.value_per_years;
pv=2000;
r =0.075;
n =3;
base=pv;
do year=1 to n;
FV=base*(1+r);
output;
base=FV+pv;
end;
run;
proc print data=work.value_per_years;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What is the context?
By looking at the generated output, you usually get what the logic does.
What specifically do you not understand?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the reply. In the first program for instance, the rate was not divided by 12 unlike the second one, what does this imply? In some cases the rate was divided by 12 within the loop, for some other it was outside the loop, what difference will this make?
Secondly, where interest is calculated separately, we have capital+interest, in another program we have earned+capital+interest, earned being the accumulating variable in the sum statement.
In the last program, the interest was not calculated separately; Earned+(capital+earned)*rate.
Since each solution gives entirely different answers, it would mean they address different Questions, I'm trying to figure the sort of questions that apply to each program.
If I'm given a question on do loop, I won't be sure which method is correct because I don't get the logic.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Still, I don't understand the context.
Division by 12, I guess this means a monthly interest rate?
These differences has mainly not to do with the do loop logic itself, they are different examples of different business calculations.
The requirements you get will help you understand what to implement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@LinusH Sorry for the late reply.
I'm not sure but these questions will help, can you please take me through the logic for each question🙏.
Q1. On January 1 of each year, $5,000 is invested in an
account. Determine the value of the account after three
years based on a constant annual interest rate of 7.5
percent.
Q2. Compare the interest for yearly versus quarterly
compounding on a $50,000 investment made for one
year at 7.5 percent interest.
How much money will a person accrue in each situation?
Q2b. What if you wanted to determine the quarterly
compounded interest after a period of 20 years
(80 quarters)?
Q3. Compute the total amount of money you will have if you start with $100 and invest it at a 3.75% interest rate for 3years.
Q4. A new account was opened in the SBI with initial deposit of Rs. 10,000/. SBI offers an interest rate of 4%. Find the balance after 5 years. Also store the every year and the balance(Saw this on the community but logic was not explained).
Thank You.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The first thing you need is to figure out the formulas (the logic) to answer your questions. Only once you've got that sorted you can start writing a program for it - and for your problems these programs should be rather simple beginner level and you should first try yourself and ask questions here in case you get stuck.
If you don't know how to create such simple SAS programs then you need first some training. There is free beginner level training out there.
I've posted your first question into ChatGPT and it returned the following formula:
Now that you've got the formula you could write the program
data work.value_after_3_years;
pv=2000;
r=0.075;
n=3;
FV=pv*(1+r)**n;
run;
And if you want it per year then you could add a do loop for yearly calculations
data work.value_per_years;
pv=2000;
r=0.075;
n=3;
do year=1 to n;
FV=pv*(1+r)**year;
output;
end;
run;
proc print data=work.value_per_years;
run;
I hope above gives you some guidance how to approach this and how you can proceed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Patrick , this is very helpful, thank you.
I have one last clarification to make, please.
If the question says $2000 is invested each year, does that not mean that the value of PV should increment by 2000 for the three years 2000, 4000, and 6000, rather than remain 2000?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@PrinceAde wrote:
Hi @Patrick , this is very helpful, thank you.
I have one last clarification to make, please.
If the question says $2000 is invested each year, does that not mean that the value of PV should increment by 2000 for the three years 2000, 4000, and 6000, rather than remain 2000?
True! And a good example that one always needs to verify answers provided by chatGPT.
And it also makes me think that eventually one intention of your exercises is to make you realize that you've got two approaches for solving such problems:
The smart way where you work out the proper formula (function) for the problem that allows you to directly retrieve the value after n-years or the dumber approach where you make the computer iterate over a function that only works for a single year.
There are also some SAS functions for available for financial calculations and it might be worth for you to consult the SAS docu.
Below an example for the dumber approach.
data work.value_per_years;
pv=2000;
r =0.075;
n =3;
base=pv;
do year=1 to n;
FV=base*(1+r);
output;
base=FV+pv;
end;
run;
proc print data=work.value_per_years;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Patrick Very insightful. Thank you very much for your help.