| 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 |
|
| 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
|