BookmarkSubscribeRSS Feed
Timbim
Obsidian | Level 7

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

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

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

 

 

 

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1 reply
  • 827 views
  • 0 likes
  • 2 in conversation