Date: Tue, 15 Dec 2009 15:48:52 -0400
Reply-To: Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Subject: Re: Do over can't be nested?
In-Reply-To: <ce1fb7450912151132s6d435bbbq689fab91fc30eef9@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
data_null_
It likes only ( ) but not of other 2 parentheses.
data _null_;
array x[i] a1-a3 (3*0);
array y[j] b1-b4 (4*1);
do over x;
do over y;
put x= y=;
end;
end;
run;
data _null_;
array x{i} a1-a3 (3*0);
array y{j} b1-b4 (4*1);
do over x;
do over y;
put x= y=;
end;
end;
run;
On Tue, Dec 15, 2009 at 3:32 PM, Data _null_; <iebupdte@gmail.com> wrote:
> The problem is the implied subscript variable _I_ is defined for both
> arrays. Define explicit subscript variable name in array definition.
> I and J below.
>
> 2996 data _null_;
> 2997 array x(i) a1-a3 (3*0);
> 2998 array y(j) b1-b4 (4*1);
> 2999 do over x;
> 3000 do over y;
> 3001 put x= y=;
> 3002 end;
> 3003 end;
> 3004 run;
>
> a1=0 b1=1
> a1=0 b2=1
> a1=0 b3=1
> a1=0 b4=1
> a2=0 b1=1
> a2=0 b2=1
> a2=0 b3=1
> a2=0 b4=1
> a3=0 b1=1
> a3=0 b2=1
> a3=0 b3=1
> a3=0 b4=1
>
>
> On 12/15/09, Ya Huang <ya.huang@amylin.com> wrote:
> > Hi there,
> >
> > I'm surprised that "do over" can't be nested. See the following.
> > The first data step tried to nest two "do over" and got error message.
> > The second one used explicit reference to the array and worked as
> > expected. Wonder why? Is it because do over always use the same index
> var,
> > so the inner loop changes the outer loop index?
> >
> > Thanks
> >
> > Ya
> >
> > 1 data _null_;
> > 2 array x a1-a3 (3*0);
> > 3 array y b1-b4 (4*1);
> > 4 do over x;
> > 5 do over y;
> > 6 put x= y=;
> > 7 end;
> > 8 end;
> > 9 run;
> >
> > a1=0 b1=1
> > a2=0 b2=1
> > a3=0 b3=1
> > ERROR: Array subscript out of range at line 6 column 4.
> > _I_=4 a1=0 a2=0 a3=0 b1=1 b2=1 b3=1 b4=1 _ERROR_=1 _N_=1
> > NOTE: The SAS System stopped processing this step because of errors.
> > NOTE: DATA statement used (Total process time):
> > real time 0.00 seconds
> > cpu time 0.00 seconds
> >
> >
> > 10
> > 11 data _null_;
> > 12 array x a1-a3 (3*0);
> > 13 array y b1-b4 (4*1);
> > 14 do i=1 to dim(x);
> > 15 do j=1 to dim(y);
> > 16 put x(i)= y(j)=;
> > 17 end;
> > 18 end;
> > 19 run;
> >
> > a1=0 b1=1
> > a1=0 b2=1
> > a1=0 b3=1
> > a1=0 b4=1
> > a2=0 b1=1
> > a2=0 b2=1
> > a2=0 b3=1
> > a2=0 b4=1
> > a3=0 b1=1
> > a3=0 b2=1
> > a3=0 b3=1
> > a3=0 b4=1
> > NOTE: DATA statement used (Total process time):
> > real time 0.00 seconds
> > cpu time 0.00 seconds
> >
>
|