I wrote this SAS amortization schedule program. First without macro the program compiles fine. Please see code below: data amortzAB;
balance=480000;
month=0;
do until (month>=30*12);
month=month+1;
/*Compute interest rate amortized;*/
rate= 0.06/12 ;
/*Compute the monthly payment;*/
monthly =(480000)*(rate*(1+rate)**(30*12))/((1+rate)**(30*12)-1);
/*Compute interest paid every month;*/
interest_amount=(balance)*rate;
/*Compute principal toward amount borrowed;*/
principal_toward_paymt=monthly-interest_amount;
/*Updated the new balance after each month;*/
balance=(balance)-principal_toward_paymt;
if (balance<monthly) then monthly=balance;
if (balance <0) then stop;
output;
END;
run;
proc print data=amortzAB;
var balance rate monthly principal_toward_paymt interest_amount month ;
title "Amortization schedule &theplan. with &theperiod. years";
title2 "and a downpayment of &thedeposit.";
run; Now I turned over to the use of macro but I keep getting this error : NOTE: Line generated by the invoked macro "AMORTZ_MACRO". 126 output; ______ 22 SYMBOLGEN: Macro variable THEPERIOD resolves to 15 MLOGIC(AMORTZ_MACRO): %DO %UNTIL() condition is TRUE; loop will not iterate again. MPRINT(AMORTZ_MACRO): monthly=balance output; MPRINT(AMORTZ_MACRO): run; ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=. Please see code below. OPTIONS MPRINT MLOGIC SYMBOLGEN;
%macro amortz_macro (theplan=,thebalance=,therate=, theperiod=, thedeposit=);
data amortzAB;
balance=&thebalance.;
month=0;
%do %until (month>=&theperiod.*12);
month=month+1;
/*Compute interest rate amortized;*/
rate= &therate./12 ;
/*Compute the monthly payment;*/
monthly =(&thebalance.)*(rate*(1+rate)**(&theperiod.*12))/((1+rate)**(&theperiod.*12)-1);
/*Compute interest paid every month;*/
interest_amount=(balance)*rate;
/*Compute principal toward amount borrowed;*/
principal_toward_paymt=monthly-interest_amount;
/*Updated the new balance after each month;*/
balance=(balance)-principal_toward_paymt;
%if (balance<monthly) %then monthly=balance;
%if (balance <0) %then stop;
output;
%END;
run;
proc print data=amortzAB;
var balance rate monthly principal_toward_paymt interest_amount month ;
title "Amortization schedule &theplan. with &theperiod. years";
title2 "and a downpayment of &thedeposit.";
run;
%mend amortz_macro;
%amortz_macro(theplan=A,thebalance=480000,therate=0.06, theperiod=30, thedeposit=120000);
%amortz_macro(theplan=B,thebalance=499200,therate=0.055, theperiod=30, thedeposit=120000);
%amortz_macro(theplan=A,thebalance=480000,therate=0.06, theperiod=15, thedeposit=120000); Can anybody help determine what is the real problem.-Thanks.
... View more