Date: Thu, 20 Jul 2006 11:25:30 +0100
Reply-To: Guido T <cymraegerict@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Guido T <cymraegerict@GMAIL.COM>
Subject: Re: array questions
In-Reply-To: <20060719235902.65280.qmail@web35112.mail.mud.yahoo.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
On 20/07/06, xamil <xaamil@yahoo.com> wrote:
> Hi, SAS_L folks:
> I am trying to restructure the data set below from
> multiple records per obs to one record per obs, so
> that at the end I will have per group per week arrays.
> note that for some ID, same group values appear. Can
> anyone help me using array to get the desired output ?
> Thanks in advances !!
>
> data a;
> input id grp $ wk1 wk2 wk3;
> cards;
> 1 a 2 1 2
> 1 b 2 3 3
> 2 a 1 1 1
> 4 a 3 4 4
> 4 b 1 4 5
> 4 b 9 1 1
> 5 a 1 1 1
> ;
>
> desired output:
> ---------------;
> id awk1 awk2 awk3 bwk1 bwk2 bwk1
> 1 2 1 2 2 3 3
> 2 1 1 1
> 4 3 4 4 10 5 6
> 5 1 1 1
>
>
Hi,
A repeated transpose "solution" ...
proc transpose data=a out=b;
by id grp;
var wk:;
run;
data c(drop=col:);
set b;
x = sum(of col:);
grp = trim(grp)||_name_;
run;
proc transpose data=c out=d(drop=_name_);
by id ;
var x;
id grp;
run;
and an array "solution" ...
data t(drop=wk: _: grp);
array a[*] awk1 awk2 awk3 bwk1 bwk2 bwk3;
array w[*] wk1 wk2 wk3;
do until (last.id);
set a;
by id grp;
_off = dim(w)*(grp eq 'b');
do _i=1 to dim(w);
a[_i+_off] = sum(w[_i], a[_i+_off]);
end;
end;
output;
run;
Regards
++ Guido