Question about transpose

  • Follow


Hi all,

I have a question about the transpose.
Say I have a data as following:

ID	PA1	PA2	PA3	PB1	PB2	PB3
1	29	86	41	24	85	29
2	34	70	31	79	60	8
3	6	31	76	30	88	8
4	68	24	90	30	80	90
5	99	99	74	39	55	67


I would like to transpose it to the following:

ID	GROUP	PA	PB
1	1	29	24
1	2	86	85
1	3	41	29
2	1	34	79
2	2	70	60
2	3	31	8
3	1	6	30
3	2	31	88
3	3	76	8
4	1	68	30
4	2	24	80
4	3	90	90
5	1	99	39
5	2	99	55
5	3	74	67


It is a sample structure of the real data. I am a little concern about
the TRANSPOSE. As I remember, it is not recommended for large data
set, but data step.

Any suggestions?

Thanks,


0
Reply yanjiemaomao (10) 3/18/2011 5:29:05 PM

On Mar 18, 10:29=A0am, palapara <yanjiemao...@gmail.com> wrote:
> Hi all,
>
> I have a question about the transpose.
> Say I have a data as following:
>
> ID =A0 =A0 =A0PA1 =A0 =A0 PA2 =A0 =A0 PA3 =A0 =A0 PB1 =A0 =A0 PB2 =A0 =A0=
 PB3
> 1 =A0 =A0 =A0 29 =A0 =A0 =A086 =A0 =A0 =A041 =A0 =A0 =A024 =A0 =A0 =A085 =
=A0 =A0 =A029
> 2 =A0 =A0 =A0 34 =A0 =A0 =A070 =A0 =A0 =A031 =A0 =A0 =A079 =A0 =A0 =A060 =
=A0 =A0 =A08
> 3 =A0 =A0 =A0 6 =A0 =A0 =A0 31 =A0 =A0 =A076 =A0 =A0 =A030 =A0 =A0 =A088 =
=A0 =A0 =A08
> 4 =A0 =A0 =A0 68 =A0 =A0 =A024 =A0 =A0 =A090 =A0 =A0 =A030 =A0 =A0 =A080 =
=A0 =A0 =A090
> 5 =A0 =A0 =A0 99 =A0 =A0 =A099 =A0 =A0 =A074 =A0 =A0 =A039 =A0 =A0 =A055 =
=A0 =A0 =A067
>
> I would like to transpose it to the following:
>
> ID =A0 =A0 =A0GROUP =A0 PA =A0 =A0 =A0PB
> 1 =A0 =A0 =A0 1 =A0 =A0 =A0 29 =A0 =A0 =A024
> 1 =A0 =A0 =A0 2 =A0 =A0 =A0 86 =A0 =A0 =A085
> 1 =A0 =A0 =A0 3 =A0 =A0 =A0 41 =A0 =A0 =A029
> 2 =A0 =A0 =A0 1 =A0 =A0 =A0 34 =A0 =A0 =A079
> 2 =A0 =A0 =A0 2 =A0 =A0 =A0 70 =A0 =A0 =A060
> 2 =A0 =A0 =A0 3 =A0 =A0 =A0 31 =A0 =A0 =A08
> 3 =A0 =A0 =A0 1 =A0 =A0 =A0 6 =A0 =A0 =A0 30
> 3 =A0 =A0 =A0 2 =A0 =A0 =A0 31 =A0 =A0 =A088
> 3 =A0 =A0 =A0 3 =A0 =A0 =A0 76 =A0 =A0 =A08
> 4 =A0 =A0 =A0 1 =A0 =A0 =A0 68 =A0 =A0 =A030
> 4 =A0 =A0 =A0 2 =A0 =A0 =A0 24 =A0 =A0 =A080
> 4 =A0 =A0 =A0 3 =A0 =A0 =A0 90 =A0 =A0 =A090
> 5 =A0 =A0 =A0 1 =A0 =A0 =A0 99 =A0 =A0 =A039
> 5 =A0 =A0 =A0 2 =A0 =A0 =A0 99 =A0 =A0 =A055
> 5 =A0 =A0 =A0 3 =A0 =A0 =A0 74 =A0 =A0 =A067
>
> It is a sample structure of the real data. I am a little concern about
> the TRANSPOSE. As I remember, it is not recommended for large data
> set, but data step.
>
> Any suggestions?
>
> Thanks,

I think you'd end up using two proc transpose (one for PA and one for
PB) so you may want to use a datastep anyways, then you can do it in
one step.

0
Reply Reeza 3/18/2011 11:21:21 PM


this is the one way u can do this using arrays.

data r;
input ID      PA1     PA2     PA3     PB1     PB2     PB3 ;
cards;
1       29      86      41      24      85      29
2       34      70      31      79      60      8
3       6       31      76      30      88      8
4       68      24      90      30      80      90
5       99      99      74      39      55      67
;
run;
proc transpose data=r out=r1;
by id;
var pa1 pa2 pa3 pb1 pb2 pb3;
run;
data split;
   set r;
   array s{3} pa1-pa3 ;
   array t(3) pb1-pb3;
   Subject + 1;
   do Time=1 to 3;
      pa=s{time};
	  pb=t{time};
      output;
   end;
   keep id pa time pb ;
run;
0
Reply raju 3/19/2011 9:43:13 AM

2 Replies
198 Views

(page loaded in 0.077 seconds)

Similiar Articles:













7/17/2012 10:34:05 AM


Reply: