10-19-2012 12:37 AM
I have been working with the code below and it runs well. The basic idea is for macro COLLATERAL to keep being called by the OUTER macro (via a %do-%while loop); the loop in the OUTER macro terminates once the variable DIFFERENCE reaches zero (the variable DIFFERENCE can be found in the last lines of code of the macro COLLATERAL). What I need this code for is to determine the value of the %ADD_COLL variable in the OUTER macro that will make the variable DIFFERENCE in the macro COLLATERAL equal to (or very close to) zero. Notice that the variable DIFFERENCE flows from the OUTER macro into the COLLATERAL macro. My problem is this; from my experience, I know that variable %ADD_COLL can assume values in the thousands and more often than not in the millions (i.e, 160,000,000 etc). This being the case, my loop runs for a very very long time, because I am currently incrementing the %ADD_COLL variable by 1 after each iteration. If I increment %ADD_COLL faster, however (say by 1,000,0000 at a time), I run into the risk of overshooting the correct value of %ADD_COLL oftentimes by too much and prematurely halting my loop in the macro OUTER. Is there a way to increment %ADD_COLL more quickly without, overshooting; I was thinking of somehow starting with a large increment for %ADD_COLL, adjusting the increment in the event of an overshoot and then incrementing %ADD_COLL by a new amount that will not lead to another overshot. I am open to all suggestions, however, along with the appropriate coding solution. Many thanks in advance; below is the code in question.
%global finish add_coll;
if newbal<0 then do;
if abs(newbal)>collateral2 then do;
if fee_cd='F' then do;
if bal<0 then daily_cr_net=0.0000124*(uncollod/1291);
if newbal<0 then newdaily_cr_net=0.0000124*(newuncollod2/1291);
create table all_daily_fees4 as
select aba, sum(daily_cr_net) as rmp_cr_net, sum(newdaily_cr_net) as newrmp_cr_net
group by aba;
if difference<0 then call symputx('finish',0);
%do %while (&finish);
%let add_coll = %eval(&add_coll+1);
10-19-2012 07:43 AM
First thing would be to strip down your code an reduce passes through data. You basically could do the whole thing in a single data _null_ step. For me to be motivated to put in the effort and strip your code you first must post code where you've got the business logic right and where the syntax is correct.
The code you've posted contains 2 syntax errors. So this can't be what you're succesfully running and it's now only about tweaking for performance.
10-19-2012 09:08 PM
Run the code you've posted and the log will tell you. Or even better: Look first at your code in a more recent SAS editor and ask yourself why there is stuff highlighted in red. Fix it, then run your code and if there are no more errors or warnings in the log check if the result is as expected. Once you're there post your code again and ask for performance tweaking. Please provide also a log so that we can see with what volumes we're dealing here.
Syntax error 1: What's the line "newuncollod2;" supossed to achieve?