From: imh bychua on
Hi

i have a table with the following columns now :

id date1 code1 date2 code2 date3 code3 date4 code4.

i would like to find out whether is there a more efficient way to
transpose the table into

id date code
-- ---- ------

in sql, it sld be similar to

select id, date1, code1 from table
union
select id ,date2, code2 from table
union
select id, date3, code3 from table

etc...
thank you
best regards
chua
From: GuyA on
Look up the TRANSPOSE procedure. Very simple and useful.
From: Patrick on
Hi Chua

I believe your union statement would need some adjustments for doing
what you want it to do...

Alternatively you could use a data step like below. Besides of
performance this will also be more convenient to code the more
elements you have (in comparison to a SQL UNION).

data want(drop=i);
set have;
array date {*} date1-date3;
array code {*} code1-code3;
do i=1 to dim(date);
date=date{i};
code=code{i};
output;
end;
run;

HTH
Patrick
From: Reeza on
On Mar 30, 3:40 am, imh bychua <imh.byc...(a)gmail.com> wrote:
> Hi
>
> i have a table with the following columns now :
>
> id   date1  code1  date2  code2   date3  code3  date4  code4.
>
> i would like to find out whether is there a more efficient way to
> transpose the table into
>
> id date code
> --  ----  ------
>
> in sql, it sld be similar to
>
> select id, date1, code1 from table
> union
> select id ,date2, code2 from table
> union
> select id, date3, code3 from table
>
> etc...
> thank you
> best regards
> chua

As GuyA stated, use the Transpose function. Easiest and most
versatile, well worth knowing.
From: Lou on

"Reeza" <fkhurshed(a)hotmail.com> wrote in message
news:969cbf5f-1aa0-417e-92f7-ec7f4163a825(a)10g2000yqq.googlegroups.com...

(snipped)

>As GuyA stated, use the Transpose function. Easiest and most
>versatile, well worth knowing.

GuyA suggested using the transpose **procedure** (aka PROC TRANSPOSE).
Procedures and functions are not the same thing. And as of v9.1.3, SAS does
not have a "transpose function".