LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2012, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 22 Mar 2012 16:41:21 -0400
Reply-To:     Tom Abernathy <tom.abernathy@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Tom Abernathy <tom.abernathy@GMAIL.COM>
Subject:      Re: Reshape data

Why not just add a unique id?

data have ; infile cards dsd truncover ; length name $32 value $200; input name value; if upcase(name)='NAME') then id+1; cards; .... run;

proc transpose data=have out=want ; by id; id name; var value; run;

On Thu, 22 Mar 2012 16:14:17 -0400, Bolotin Yevgeniy <YBolotin@SCHOOLS.NYC.GOV> wrote:

>Usually i'd recommend proc transpose, but since you don't have a common >key you can just LAG > > >data HAVE; >infile datalines delimiter=','; >input category $ Value $ ; >datalines; >NAME,Alfred >Age,14 >Height,69 >Weight,112.5 >NAME,Alice >Age,13 >Height,56.5 >Weight,84 >NAME,Barbara >Age,13 >Height,65.3 >Weight,98 >NAME,Carol >Age,14 >Height,62.8 >Weight,102.5 >NAME,Henry >Age,14 >Height,63.5 >Weight,102.5 >; >Run; > >data WANT (drop = category value); > set HAVE; > name = lag3(value); > age = lag2(value); > height = lag1(value); > weight = value; > if mod(_n_,4) = 0; *only keep every fourth observation - this >will NOT WORK CORRECTLY if you have missing items in your data!; >run; > > > >-----Original Message----- >From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of >Charlie Huang >Sent: Thursday, March 22, 2012 3:53 PM >To: SAS-L@LISTSERV.UGA.EDU >Subject: Reshape data > >Hi SASLers, > >I have a question regarding data reshaping like below. I wonder if there >is >any good method to do it. Thanks a lot. > >I have: > >NAME Alfred >Age 14 >Height 69 >Weight 112.5 >NAME Alice >Age 13 >Height 56.5 >Weight 84 >NAME Barbara >Age 13 >Height 65.3 >Weight 98 >NAME Carol >Age 14 >Height 62.8 >Weight 102.5 >NAME Henry >Age 14 >Height 63.5 >Weight 102.5 > >I want: > >Name Age Height Weight >Alfred 14 69 112.5 >Alice 13 56.5 84 >Barbara 13 65.3 98 >Carol 14 62.8 102.5 >Henry 14 63.5 102.5 > >-- >Best regards, >Charlie Huang


Back to: Top of message | Previous page | Main SAS-L page