BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
newboy1218
Quartz | Level 8

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_rateannual_payment
101200
204000
30.0083251000
40.008325500

 

WANT:

#int_rateannual_paymentpv
1012002400
2040008000
30.00832510001806.0852117
40.008325500903.04260585

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

2 REPLIES 2
ballardw
Super User

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

 

 

 


 

mkeintz
PROC Star

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

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1024 views
  • 2 likes
  • 3 in conversation