Date: Wed, 3 Mar 2010 12:16:45 -0800
Reply-To: "Schwarz, Barry A" <barry.a.schwarz@BOEING.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Schwarz, Barry A" <barry.a.schwarz@BOEING.COM>
Subject: Re: long to wide
In-Reply-To: <201003031929.o23BmFhh011954@malibu.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"
data wide (keep subj_id auto1-auto2 manual1-manual2);
array auto(*) auto1-auto2;
array manual(*) manual1-manual2;
retain auto1-auto2 manual1-manual2;
set long;
by subj_id;
if first.subj_id then
do;
a = 1;
m = 1;
end;
if automan = 'auto' then
do;
auto(a) = testresult;
a+1;
end
if automan = 'manual' then
do
manual(m) = testresult;
m+1;
end;
if last.subj_id then
output;
run;
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of William Whitworth
Sent: Wednesday, March 03, 2010 11:29 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: long to wide
I have data in the following long format (4 obs per subject, with automan
and accession as unique identifiers):
data long;
input Subj_ID $ AUTOMAN $ ACCESSION $ TESTRESULT;
datalines;
24C-004 auto C07-1021 10
24C-004 manual C07-1021 22
24C-004 auto C07-1022 13
24C-004 manual C07-1022 20
24C-006 auto C07-1033 17
24C-006 manual C07-1033 25
24C-006 auto C07-1034 18
24C-006 manual C07-1034 11
;;;;
Proc Print; run;
I'd like to get the data into the following structure:
(The lowest accession is for the first two tests, the higher is for the
second two tests).
Subj_ID AUTO1 AUTO2 MANUAL1 MANUAL2
24C-004 10 13 22 20
24C-006 17 18 25 11