Date: Tue, 27 Jun 2006 23:28:09 -0400
Reply-To: Arthur Tabachneck <art297@NETSCAPE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Arthur Tabachneck <art297@NETSCAPE.NET>
Subject: Re: Dataset Re-format Question
Julie,
Try proc transpose. For example:
data have;
input ID $ A B C D Z;
cards;
12423 434 12.1 42 242 3.4
04253 3.4 9.9 42 45 243
64753 3.6 532 23 333 43
74467 9.7 436 26 2.4 73
09463 8.4 45 7.8 232 5.6
25523 22 416 43 187 4.5
;
run;
proc sort data=have;
by id;
run;
proc transpose data=have out=want;
by id;
run;
HTH,
Art
---------
On Tue, 27 Jun 2006 20:16:40 -0700, wardnine@HOTMAIL.COM wrote:
>Hey - I have a SAS dataset where the first column is a five digit
>identification number (variable name = ID). I then have 26 more columns
>that contain amounts associated with each ID in the file. For
>simplicity's sake, let's say the variable name for the second column is
>A, the third column is B, the fourth column is C, etc... until the
>final column which is named Z. So the dataset (when you view it in SAS)
>basically looks like the table below (the formatting of the table will
>probably be off but I hope you get the idea):
>
> ID A B C D ...... Z
>12423 434 12.1 42 242 3.4
>04253 3.4 9.9 42 45 243
>64753 3.6 532 23 333 43
>74467 9.7 436 26 2.4 73
>09463 8.4 45 7.8 232 5.6
>25523 22 416 43 187 4.5
>
>Is it possible to reformat the dataset above so that the variable names
>in the dataset (except for the ID variable which I need to keep as a
>variable name) become data values? I would want 3 variables in the
>resulting dataset: ID, VARIABLE, and AMOUNT. ID would be the same as in
>the above table, VARIABLE can contain any of the variable names in the
>above dataset and AMOUNT is the numerical amount for a given
>combination of ID and VARIABLE. The resulting dataset would be as
>follows (using the numbers in the table above):
>
>ID VARIABLE AMOUNT
>12423 A 434
>12423 B 12.1
>12423 C 42
>12423 D 242
>12423 Z 3.4
>04253 A 3.4
>04253 B 9.9
>
>and so on...
>
>Is there SAS code that can re-arrange the first dataset I have to look
>like the second? Any help here is appreciated, thanks!!!
>
>Julie
|