Date: Thu, 9 Sep 2010 09:54:12 -0700
Reply-To: "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Subject: Re: transposing observations to arrays
In-Reply-To: <201009091614.o89Akj2C027724@malibu.cc.uga.edu>
Content-Type: text/plain; charset=utf-8
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> Randall Powers
> Sent: Thursday, September 09, 2010 9:15 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: transposing observations to arrays
>
> Hello All.
>
> I have this dataset:
>
> obs a b c d e f g h i
> 1
> 2
> 3
> 4
> 5
> 6
> 7
>
>
> Hence, nine variables, seven observations.
>
> What I'd like to end up with is a dataset with one observation
> containing
> nine arrays with the previous observation number as the array index.
> Hence,7*9=63 variables:
>
> obs a1 a2 a3 a4 a5 a6 a7 b1 b2 b3....b7.....i7
> 1
>
> How do I do this?
>
> Thanks!
Here is one solution for your very specific question and data. Generalizing to other situations and data is left as an exercise for the reader. See Joe Matise's reply for clues.
data want(keep=a1--i7);
retain a1-a7 b1-b7 c1-c7 d1-d7 e1-e7 f1-f7 g1-g7 h1-h7 i1-i7 ;
array hold[9,7] a1-a7 b1-b7 c1-c7 d1-d7 e1-e7 f1-f7 g1-g7 h1-h7 i1-i7;
set have end=eof;
array v[9] a--i;
do _i_=1 to 9;
hold[_i_,_n_] = v[_i_];
end;
if eof then output;
run;
Hope this is helpful,
Dan
Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204
|