| Date: | Mon, 31 Oct 2005 11:11:47 -0800 |
| Reply-To: | "Terjeson, Mark (IM&R)" <Mterjeson@RUSSELL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "Terjeson, Mark (IM&R)" <Mterjeson@RUSSELL.COM> |
| Subject: | Re: Flatten dataset |
|
| Content-Type: | text/plain; charset="us-ascii" |
Hi,
Date strings, which if keying off months,
will not sort properly. By converting to
a real date and then alpha the resulting
cosmetics you can order as desired.
* real sas date allows proper ordering ;
* so convert date string to sas date. ;
data sample(drop=Month rename=(mm=Month));
input ID $ Month $ Cost;
mm = input('1'||Month,date8.);
format mm monyy7.;
cards;
1 Jan2000 50.00
1 Feb2000 75.00
1 Apr2000 20.00
1 Mar2000 1000.00
7 Jun2000 50.00
7 May2000 75.00
7 Mar2000 75.00
8 Apr2000 820.00
8 Mar2000 81000.00
8 Jun2000 850.00
8 May2000 875.00
;
run;
* real sas date allows proper ordering ;
proc sort data=sample;
by ID Month;
run;
proc transpose data=sample out=result(drop=_name_);
by ID;
id Month;
var Cost;
run;
Hope this is helpful.
Mark Terjeson
Senior Programmer Analyst, IM&R
Russell Investment Group
Russell
Global Leaders in Multi-Manager Investing
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Newbie
Sent: Monday, October 31, 2005 10:38 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Flatten dataset
Hi,
I tried PROC TRANSPOSE but it does not work as needed.
Here is my code -
PROC TRANSPOSE DATA=TEST OUT=FLAT;
PREFIX=DATE;
VAR COST;
BY ID;
RUN;
This just flattens the data but I need them flattened in a particular
order. I need Jan2000 cost in the JanCost field, Feb2000 costs in
FebCost field and so on. Not every ID has costs for every month, some
may have costs for 1 month or some may have costs for 12 months.
|