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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 508 views
  • 0 likes
  • 2 in conversation