| Date: | Thu, 5 Apr 2001 17:41:47 -0700 |
| Reply-To: | "Huang, Ya" <ya.huang@AGOURON.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "Huang, Ya" <ya.huang@AGOURON.COM> |
| Subject: | Re: Transposing Data |
|
| Content-Type: | multipart/alternative;
|
|---|
Reiling,
Take a look at the following code:
data xx;
input GRP $ SEQ IND DEP;
cards;
AAA 1 1.4 5
AAA 2 1.8 6
AAA 3 2.0 7
AAA 4 2.3 4
BBB 1 0.9 5
BBB 2 1.2 6
CCC 3 1.0 7
CCC 4 0.9 4
CCC 5 0.9 4
DDD 2 2.3 6
DDD 3 2.2 7
DDD 4 2.1 4
DDD 5 2.5 4
;
data temp;
set xx;
v='IND_'||grp;
output;
v='DEP_'||grp;
output;
proc sql noprint;
select distinct v, count(distinct v)
into : vlist separated by ' ', : nn
from temp
;
%put &vlist &nn;
data xx;
set xx;
length from $10;
array vv(&nn) &vlist;
do i=1 to dim(vv);
call vname(vv(i),from);
if grp=substr(from,5) and substr(from,1,4)='IND_' then vv(i)=ind;
if grp=substr(from,5) and substr(from,1,4)='DEP_' then vv(i)=dep;
end;
drop ind dep from i;
options nocenter;
proc print heading=v;
run;
---------------------
The SAS System 17:12 Thursday, April 5, 2001 16
D D D D I I I I
E E E E N N N N
P P P P D D D D
_ _ _ _ _ _ _ _
O G S A B C D A B C D
b R E A B C D A B C D
s P Q A B C D A B C D
1 AAA 1 5 . . . 1.4 . . .
2 AAA 2 6 . . . 1.8 . . .
3 AAA 3 7 . . . 2.0 . . .
4 AAA 4 4 . . . 2.3 . . .
5 BBB 1 . 5 . . . 0.9 . .
6 BBB 2 . 6 . . . 1.2 . .
7 CCC 3 . . 7 . . . 1.0 .
8 CCC 4 . . 4 . . . 0.9 .
9 CCC 5 . . 4 . . . 0.9 .
10 DDD 2 . . . 6 . . . 2.3
11 DDD 3 . . . 7 . . . 2.2
12 DDD 4 . . . 4 . . . 2.1
13 DDD 5 . . . 4 . . . 2.5
HTH
Ya Huang
-----Original Message-----
From: Reiling Lee [mailto:reiling@PACBELL.NET]
Sent: Thursday, April 05, 2001 4:54 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Transposing Data
I have a dataset looks like DATA1 and I'd like to transpose the data into
DATA2. Anyone knows any efficient to do it for possible 7000 values in GRP
and 200 values in SEQ?
DATA1
GRP SEQ IND DEP
--- --- --- ---
AAA 1 1.4 5
AAA 2 1.8 6
AAA 3 2.0 7
AAA 4 2.3 4
BBB 1 0.9 5
BBB 2 1.2 6
CCC 3 1.0 7
CCC 4 0.9 4
CCC 5 0.9 4
DDD 2 2.3 6
DDD 3 2.2 7
DDD 4 2.1 4
DDD 5 2.5 4
DATA2
GRP SEQ IND_AAA IND_BBB IND_CCC IND_DDD DEP_AAA DEP_BBB DEP_CCC DEP_DDD
--- --- ------- ------- ------- ------- ------- ------- ------- -------
AAA 1 1.4 0 0 0 5 0 0 0
AAA 2 1.8 0 0 0 6 0 0 0
AAA 3 2.0 0 0 0 7 0 0 0
AAA 4 2.3 0 0 0 4 0 0 0
BBB 1 0 0.9 0 0 0 5 0 0
BBB 2 0 1.2 0 0 0 6 0 0
CCC 3 0 0 1.0 0 0 0 7 0
CCC 4 0 0 0.9 0 0 0 4 0
CCC 5 0 0 0.9 0 0 0 4 0
DDD 2 0 0 0 2.3 0 0 0 6
DDD 3 0 0 0 2.2 0 0 0 7
DDD 4 0 0 0 2.1 0 0 0 4
DDD 5 0 0 0 2.5 0 0 0 4
[text/html]
|