BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
PrinceAde
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@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;

Patrick_0-1700003713428.png

 

View solution in original post

8 REPLIES 8
LinusH
Tourmaline | Level 20

What is the context?

By looking at the generated output, you usually get what the logic does.

What specifically do you not understand?

Data never sleeps
PrinceAde
Obsidian | Level 7

@LinusH 

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.

 

LinusH
Tourmaline | Level 20

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.

Data never sleeps
PrinceAde
Obsidian | Level 7

@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.

Patrick
Opal | Level 21

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:

Patrick_0-1699922833169.png

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;

Patrick_1-1699923045094.png

I hope above gives you some guidance how to approach this and how you can proceed. 

PrinceAde
Obsidian | Level 7

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?

Patrick
Opal | Level 21

@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;

Patrick_0-1700003713428.png

 

PrinceAde
Obsidian | Level 7

@Patrick  Very insightful. Thank you very much for your help.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1228 views
  • 3 likes
  • 3 in conversation