Hi, I am trying to calculate the present value by using the FINANCE function in SAS. However, I found that when my rows having interest as 0%, the log threw me error for example saying:
NOTE: Invalid argument to function FINANCE('pv',0,24,-100) at line 28 column 7.
What should I do to solve it? Here is the code I used:
data aa;
input int_rate annual_payment;
datalines;
0 1200
0 4000
0.008325 1000
0.008325 500
;
run;
data bb;
set aa;
pv = finance('pv', int_rate, 24, - annual_payment / 12);
run;
Sample data - HAVE:
# | int_rate | annual_payment |
1 | 0 | 1200 |
2 | 0 | 4000 |
3 | 0.008325 | 1000 |
4 | 0.008325 | 500 |
WANT:
# | int_rate | annual_payment | pv |
1 | 0 | 1200 | 2400 |
2 | 0 | 4000 | 8000 |
3 | 0.008325 | 1000 | 1806.0852117 |
4 | 0.008325 | 500 | 903.04260585 |
This is interesting, since logically speaking, there should be no problem with rate=0. The
FINANCE PV function documentation has no restrictions on the interest rate. If there is documentation somewhere else about the finance function not tolerating int_rate=0, I haven't seen it.
<Editted note>:
The most that I have seen about interest rate is in the FINANCE Function Documentation which only says
interest-rates
specifies rates that are provided as numeric values and not as percentages.
This might be worth presenting to SAS as a possibly bug, or at least a need for improved documentation.
</end of editted note>
And interest rate=0 is really a simple calculation for PV - just a simple sum of payments. There must be something about the underlying algorithm not being robust against int_rate=0, since using values that are almost zero, both positive and negative (0.000000000000001 and -0.000000000000001) produce values very close to PV=2400.
But you could protect yourself against this by changing
pv = finance('pv', int_rate, 24, - annual_payment / 12);
to
if int_rate=0 then pv=24*annual_payment/12; else
pv = finance('pv', int_rate, 24, - annual_payment / 12);
Don't call the function with an invalid parameter. That is accomplished with a simple If.
What rule do want when to have as a result when the rate is 0? I might guess that you want 2 time the annual payment but I have no idea if that is actually the rule you want to program.
data bb; set aa; if rate > 0 then pv = finance('pv', int_rate, 24, - annual_payment / 12); else <do what you want when the rate is 0>; run;
NOT a finance person so don't expect a recommendation on an actual value to provide when there the rate is 0.
@newboy1218 wrote:
Hi, I am trying to calculate the present value by using the FINANCE function in SAS. However, I found that when my rows having interest as 0%, the log threw me error for example saying:
NOTE: Invalid argument to function FINANCE('pv',0,24,-100) at line 28 column 7.
What should I do to solve it? Here is the code I used:
data aa;
input int_rate annual_payment;
datalines;
0 1200
0 4000
0.008325 1000
0.008325 500
;
run;data bb;
set aa;
pv = finance('pv', int_rate, 24, - annual_payment / 12);
run;
Sample data - HAVE:
# int_rate annual_payment 1 0 1200 2 0 4000 3 0.008325 1000 4 0.008325 500
WANT:
# int_rate annual_payment pv 1 0 1200 2400 2 0 4000 8000 3 0.008325 1000 1806.0852117 4 0.008325 500 903.04260585
This is interesting, since logically speaking, there should be no problem with rate=0. The
FINANCE PV function documentation has no restrictions on the interest rate. If there is documentation somewhere else about the finance function not tolerating int_rate=0, I haven't seen it.
<Editted note>:
The most that I have seen about interest rate is in the FINANCE Function Documentation which only says
interest-rates
specifies rates that are provided as numeric values and not as percentages.
This might be worth presenting to SAS as a possibly bug, or at least a need for improved documentation.
</end of editted note>
And interest rate=0 is really a simple calculation for PV - just a simple sum of payments. There must be something about the underlying algorithm not being robust against int_rate=0, since using values that are almost zero, both positive and negative (0.000000000000001 and -0.000000000000001) produce values very close to PV=2400.
But you could protect yourself against this by changing
pv = finance('pv', int_rate, 24, - annual_payment / 12);
to
if int_rate=0 then pv=24*annual_payment/12; else
pv = finance('pv', int_rate, 24, - annual_payment / 12);
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.