Hello, first off - I'm a begginer, please take it into account;)
My problem is that I can't do simple math within loop body. I need to calculate interest capitalization after 5 years. Starting amount is 5000 USD.
data xyz.Capit;
amount = 5000;
i=1;
do while (i <= 5);
i + 1;
option1 = amount*(1,04/1);
end;
run;
This code can't be executed, shows errors (sth about aritmethical error). What's wrong with it?
Hi @muskagap Are you after this formula and result by any chance?
data Capit;
amount = 5000;
i=1;
do while (i <= 5);
amount = amount*(1.04/1);
output;
i + 1;
end;
run;
proc print noobs;run;
RESULT:
amount | i |
---|---|
5200.00 | 1 |
5408.00 | 2 |
5624.32 | 3 |
5849.29 | 4 |
6083.26 | 5 |
What does the log show as errors?
Please include the log.
@muskagap wrote:
Hello, first off - I'm a begginer, please take it into account;)
My problem is that I can't do simple math within loop body. I need to calculate interest capitalization after 5 years. Starting amount is 5000 USD.
data xyz.Capit;
amount = 5000;
i=1;
do while (i <= 5);
i + 1;
option1 = amount*(1,04/1);
end;
run;
This code can't be executed, shows errors (sth about aritmethical error). What's wrong with it?
Hi @muskagap Are you after this formula and result by any chance?
data Capit;
amount = 5000;
i=1;
do while (i <= 5);
amount = amount*(1.04/1);
output;
i + 1;
end;
run;
proc print noobs;run;
RESULT:
amount | i |
---|---|
5200.00 | 1 |
5408.00 | 2 |
5624.32 | 3 |
5849.29 | 4 |
6083.26 | 5 |
@muskagap you have a comma rather than a dot.
try this
data xyz.Capit;
amount = 5000;
i=1;
do while (i <= 5);
i + 1;
option1 = amount*(1.04/1);
end;
run;
You may also want to investigate the SAS Finance function. The function has options to do a number of standard financial calculations such as accrued interest, interest paid between dates, more than 30 such calculations are available from the Finance function. Plus there are about another 30 functions for financial calculations.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.