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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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