*(Q) I have a macro which includes a !DO - !DOEND loop. The purpose of the loop is to repeat a iterations until a the equation converge within a predefined precision. Each iteration takes quite a long time. How can I stop the iteration process as the convergence criteria has been met. * (A) Raynald Levesque 2001/09/22 To illustrate the a solution, I first use a macro which does not stop once convergence has been attained. I then modify the macro so that the macro exits the loop once convergence has been achieved. (Actually, the loop continues but without executing any commands). * File name: MacroExitsLoopWhenDataMeetConvergenceCriteria.SPS. SET SEED=12365981. SET MPRINT=yes. */////////////////////////////////. DEFINE !eloop1 (max=!TOKENS(1)) !DO !cnt=1 !TO !max COMPUTE cnt=!cnt. * Next DO IF - END IF is a proxy for the real calculations. * Assume that when we get conver=1, it means we have convergence. DO IF $CASENUM=1. COMPUTE conver=TRUNC(UNIFORM(10)). ELSE. COMPUTE conver=LAG(conver). END IF. LIST. !DOEND !ENDDEFINE. */////////////////////////////////. !eloop1 max=10. /* This macro continues to loop even when conver=1*/. exe. ***********************************************************************. * * With the following modifications the above macro stops * to execute the loop * once the convergence has been reached. * ***********************************************************************. SET SEED=12365981. SET MPRINT=yes. DEFINE !ok()0!ENDDEFINE. DEFINE !eloop2 (max=!TOKENS(1)) !DO !cnt=1 !TO !max COMPUTE cnt=!cnt. DO IF !ok<>1. + DO IF $CASENUM=1. + COMPUTE conver=TRUNC(UNIFORM(10)). + ELSE. + COMPUTE conver=LAG(conver). + END IF. + DO IF $CASENUM=1. + FORMAT conver (F2.0). + WRITE OUTFILE='c:\\temp\\temp.SPS' /"DEFINE !ok()"conver"!ENDDEFINE.". + END IF. + PRINT /a 1-2 cnt 5-7 conver 9-10. END IF. EXECUTE. INCLUDE FILE='c:\\temp\\temp.SPS' . !DOEND !ENDDEFINE. SET MPRINT=yes. !eloop2 max=10. /* This macro exits loop when conver=1*/. exe.