Date: Thu, 3 Mar 2011 11:53:22 -0800
Reply-To: "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Nordlund, Dan (DSHS/RDA)" <NordlDJ@DSHS.WA.GOV>
Subject: Re: Data manipulation
In-Reply-To: <845010.12110.qm@web113614.mail.gq1.yahoo.com>
Content-Type: text/plain; charset=utf-8
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> Steve Steve
> Sent: Thursday, March 03, 2011 10:35 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Data manipulation
>
> I have a dataset which keeps changing. It should have 5 variables, ae1-
> ae5, but
> sometime it has ae1, ae3 and ae4, sometime ae3, ae4 and ae5, and etc. I
> should
> fill in any missing ae* with 0. For example, I should have the
> following output
> for the dataset ae (see dataset below):
>
> Obs   id   ae1   ae2   ae3  ae4   ae5
>
> Â 1Â Â Â Â 11Â Â Â Â 2Â Â Â Â Â 3Â Â Â Â Â 0Â Â Â Â 0Â Â Â Â Â 5
> Â 2Â Â Â Â 12Â Â Â Â 4Â Â Â Â Â 5Â Â Â Â Â 0Â Â Â Â 0Â Â Â Â Â 6
> Â 3Â Â Â Â 13Â Â Â Â 7Â Â Â Â Â 8Â Â Â Â Â 0Â Â Â Â 0Â Â Â Â Â 9
>
>
> Instead of the following:
>
> Obs   id   ae1   ae2   ae5
>
> Â 1Â Â Â Â 11Â Â Â Â 2Â Â Â Â Â 3Â Â Â Â Â 5
> Â 2Â Â Â Â 12Â Â Â Â 4Â Â Â Â Â 5Â Â Â Â Â 6
> Â 3Â Â Â Â 13Â Â Â Â 7Â Â Â Â Â 8Â Â Â Â Â 9
>
>
> Thanks!!!
>
>
>
>
> dataae;
> inputid ae1 ae2 ae5;
> cards;
> 11 2 3 5
> 12 4 5 6
> 13 7 8 9
> ;
> run;
>
> procprint;run;
>
>
Something like this should get you started,
data ae;
retain ae1-ae5 0;
input id ae1 ae2 ae5;
cards;
11 2 3 5
12 4 5 6
13 7 8 9
;
run;
Hope this is helpful,
Dan
Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204
|