Date: Wed, 3 Mar 2010 13:39:44 -0600
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: long to wide
In-Reply-To: <201003031929.o23BmFhh011954@malibu.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1
You have to process it something like this:
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
;;;;
run;
data have;
set long;
by subj_id accession;
if first.subj_id then line=0;
if first.accession then line+1;
varname = cats(automan,line);
run;
proc transpose data=have out=want;
by subj_id;
id varname;
var testresult;
run;
-Joe
On Wed, Mar 3, 2010 at 1:29 PM, William Whitworth <wcw2@cdc.gov> wrote:
> 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
>
> I've tried a few things (datastep array, proc transpose, SQL) but nothing
> seems to work.
> Can anybody offer any suggestions? Thanks!
>