BookmarkSubscribeRSS Feed
setod003
Calcite | Level 5

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.

3 REPLIES 3
Astounding
PROC Star

Just because you are writing a macro doesn't mean you have to switch to %IF and %DO.  Get rid of all the percent signs and you should be fine (keep the ampersands, however).

novinosrin
Tourmaline | Level 20

@Astounding Simply Brilliant!!!!!! line

setod003
Calcite | Level 5

Thanks for responding.

 

I noticed two things. First is that the %do %until was the problem. When I replaced it by the %do i=1 %to (&theperiod.*12) ; then the code compiled successfully and produced the expected result.

The second thing that made it work is by removing the % sign from the if  then.

 

Can someone explain to me why especially for the case of the %do %until which did not work?

Thanks.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 1351 views
  • 1 like
  • 3 in conversation