Date: Tue, 2 Dec 2008 15:21:50 -0600
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: How to transpose the data in my way?
In-Reply-To: <B84879D70E8C1C418A6C8DA90F73313402A797A7@A-EXCH-VS1.amylin.com>
Content-Type: text/plain; charset=ISO-8859-1
Sounds like the compiler converts
DO OVER (array)
to
DO _NUMVAR_ IN (ARRAY VALS);
with any call to an array inside the do over being translated to
ARRAY[_NUMVAR_] ... interesting.
I wonder if that's why you cannot use explicitly subscripted arrays this
way?
-Joe
On Tue, Dec 2, 2008 at 3:10 PM, Huang, Ya <Ya.Huang@amylin.com> wrote:
> Further test shows that if do over a smaller array, the bigger one will
> not be iterated through out. If do over the bigger one, the out of range
> error for the smaller one:
>
> Data have;
> input ID $ A1 A2 A3 B1 B2 B3 B4;
> cards;
> QQ 1 2 3 5 2 4 9
> GG 3 8 3 6 7 4 9
> WW 4 5 6 6 1 8 9
> ;
>
> Data want;
> set have;
> array abc a1-a3;
> array xyz b1-b4;
> do over xyz;
> A=abc;
> B=xyz;
> output;
> end;
> keep ID A B;
> Run;
>
> ERROR: Array subscript out of range at line 33 column 11.
> ID=QQ A1=1 A2=2 A3=3 B1=5 B2=2 B3=4 B4=9 _I_=4 A=3 B=4 _ERROR_=1 _N_=1
>
>
>
> -----Original Message-----
> From: Ya Huang [mailto:ya.huang@AMYLIN.COM]
> Sent: Tuesday, December 02, 2008 1:07 PM
> To: SAS-L@LISTSERV.UGA.EDU; Joe Matise
> Cc: Huang, Ya
> Subject: Re: How to transpose the data in my way?
>
> On Tue, 2 Dec 2008 14:54:54 -0600, Joe Matise <snoopy369@GMAIL.COM>
> wrote:
>
> >Does do over actually allow you to do that (iterate through two arrays
> >at once)? If so, that's pretty interesting and useful to know :)
>
> It surprised me too. Just tested and it worked.
>
> >
> >If not, you would just use:
> >do i = 1 to 3;
> >...
> >end;
> >
> >(or 1 to whatever your upper limit of variable is).
> >
> >-Joe
> >
> >On Tue, Dec 2, 2008 at 2:27 PM, Akshaya Nathilvar <
> >akshaya.nathilvar@gmail.com> wrote:
> >
> >> One possible solution:
> >> Data have;
> >> input ID $ A1 A2 A3 B1 B2 B3;
> >> cards;
> >> QQ 1 2 3 5 2 4
> >> GG 3 8 3 6 7 4
> >> WW 4 5 6 6 1 8
> >> ;
> >>
> >> Data want;
> >> set have;
> >> array abc a1-a3;
> >> array xyz b1-b3;
> >> do over abc;
> >> A=abc;
> >> B=xyz;
> >> output;
> >> end;
> >> keep ID A B;
> >> Run;
> >>
> >>
> >> Akshaya
> >>
> >> On Tue, Dec 2, 2008 at 2:55 PM, Ruby <windofoct@gmail.com> wrote:
> >>
> >> > Hello folks,
> >> >
> >> > Does anybody know how to transpose the data? I extracted my data in
>
> >> > a simple way as showed below. As always, I appreciate all your
> >> > helps very much.
> >> >
> >> > ID A1 A2 A3 B1 B2 B3
> >> > QQ 1 2 3 5 2 4
> >> > GG 3 8 3 6 7 4
> >> > WW 4 5 6 6 1 8
> >> >
> >> > ID A B
> >> > QQ 1 5
> >> > QQ 2 2
> >> > QQ 3 4
> >> > GG 3 6
> >> > GG 8 7
> >> > GG 3 4
> >> > WW 4 6
> >> > WW 5 1
> >> > WW 6 8
> >> >
> >>
>
|