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:14:17 -0400
Reply-To:   Bolotin Yevgeniy <YBolotin@SCHOOLS.NYC.GOV>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Bolotin Yevgeniy <YBolotin@SCHOOLS.NYC.GOV>
Subject:   Re: Reshape data
Comments:   To: Charlie Huang <charlie.chao.huang@GMAIL.COM>
In-Reply-To:   A<CAKepp6qi2B1D+6MRgkQ=m7eTbCUwEzEyXKERu+WFBub15frBxg@mail.gmail.com>
Content-Type:   text/plain; charset="us-ascii"

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