Hi Community,
I am getting the following error when running this code:
Code:
%MACRO Payment(InterestRate = , TermInMonths = , LoanAmt = );
%if &InterestRate le 0 %then
%do;
Loan_Repayment = &LoanAmt / &TermInMonths;
%end;
%else
%do;
Loan_Repayment = &LoanAmt * (&InterestRate/100) / (1-((1+(&InterestRate/100))**(-&TermInMonths)));
%end;
%MEND;
data CUBE_05_&t_fin_year_dly;
set CUBE_04_&t_fin_year_dly;
%PAYMENT(InterestRate = acc_int_rate/12, TermInMonths = TermOfNoteInMonths, LoanAmt = acc_loan_amt);
if InterestOnlyFlag="Y" then Repaymt=acc_int;
else Repaymt=acc_repaymt;
if acc_accbal ne . and crf_accbal eq . then accbal=acc_accbal;
else if acc_accbal eq . and crf_accbal ne . then accbal=crf_accbal;
else accbal=acc_accbal;
if On_bal_amt = . then On_bal_amt=0;
else On_bal_amt=On_bal_amt;
if accbal=. then accbal=0;
else accbal=accbal;
if BOQ_SCHED_BALANCE_AMT = . then UseScheduleBalance = accbal;
else UseScheduleBalance=BOQ_SCHED_BALANCE_AMT;
if lnp_LQRCode ne "" then LQRCode=lnp_LQRCode;
else if crf_LQRCode ne "" then LQRCode = crf_LQRCode;
else if acc_LQRCode ne "" then LQRCode = acc_lqrcode;
else LQRCode = " ";
run;
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
&InterestRate le 0
ERROR: The macro PAYMENT will stop executing
Appreciate your help.
Magstar
The value of macro variable InterestRate is the string acc_int_rate/12, which is not a number.
You want something like this:
%macro Payment(InterestRate = , TermInMonths = , LoanAmt = );
%if &InterestRate le 0 %then
&LoanAmt / &TermInMonths ;
%else
&LoanAmt * (&InterestRate/100) / (1-((1+(&InterestRate/100))**(-&TermInMonths))) ;
%mend;
data CUBE_05_;
retain ACC_INT_RATE TERMOFNOTEINMONTHS ACC_LOAN_AMT 1;
LOAN_REPAYMENT= input(resolve(cats('%sysevalf(%PAYMENT( InterestRate =', ACC_INT_RATE/12
,', TermInMonths =', TERMOFNOTEINMONTHS
,', LoanAmt =', ACC_LOAN_AMT, '))' )), 32.);
putlog LOAN_REPAYMENT=;
run;
LOAN_REPAYMENT=1.0008333333
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.