Date: Mon, 10 Jul 2006 18:37:30 -0500
Reply-To: OR Stats <stats112@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: OR Stats <stats112@GMAIL.COM>
Subject: Exiting & Restarting Do Loop w. Different Initial Conditions
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Dear All,
I have a do loop in a macro that generates rows of a table. A set of
initial conditions are set before the loop begins. However, what would be
ideal is when a predefined exception occurs at an iteration within the loop,
that do loop is restarted under a different set of initial conditions and
the table is regenerated. Because, what drives the violation or lack
thereof is the initial conditions as the process is a recursive routine
doped with a random #. However, the code I have is not successful in
achieving this. This is the code that I have so far and simplified for
illustration of the main point:
%let a=1;
%let b=-2;
%let c=3;
%let d=4;
%let e=5;
data mc_pyz;
do _n_=1 to 3000;
p=ranuni(&seed);
.
.
.
*Each step populates table with y, h, and e values, which are
recursive are generated;
*y=some function of h & e functions;
*h=recursive function of initial conditions & random number
generated;
*e=recursive function of initial conditions and random number
generated;
*Exception occurs when any calculated h<0;
*which invalidates the calculation of e & y so the entire
loop needs to be restarted under a different set of initial conditions;
if h<0 then do;
%let a=5;
%let b=6;
%let c=7;
%let d=8;
%let e=9;
_n_=1
end;
*When no exception has occurred the recursion continues from
_n_ + up to 3000 with the current initial conditions;
else do;
*y=function;
*h=function;
*e=function;
end;
output ;
end;
run;quit;
SAS is not reading ' _n_=1 ' as a restart of the loop. I tried using ' %let
_n_=1 ' But the loop still does not restart either. To save comp time,
it's ideal upon reaching the exception, the loop is terminated and
restarted, and the orginal table is written over. Has anyone come across
this? To our senior members, is this already a solved problems to be found
in the Archives? Thanx!
|