Date: Thu, 13 Feb 1997 10:24:02 -0800
Reply-To: gxx18300@ggr.co.uk, BWRogers@MSN.COM
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Bruce Rogers <gxx18300@GGR.CO.UK>
Organization: Medical IR, Glaxo Wellcome
Subject: Re: filling missing values with lagged values
Content-Type: text/plain; charset=us-ascii
Jennifer Soller wrote:
>
> Hello to all.
> Here's a little problem I was given by a friend
> who is pulling her hair out.
> Checked out past posts on dejanews to no avail.
> Hope someone can work their usual magic.
>
> I have the following dataset:
>
> OBS X
> 1 1
> 2 .
> 3 .
> 4 2
> 5 2
> 6 2
> 7 .
> 8 3
> 9 3
> 10 .
> 11 .
> 12 .
> 13 .
> 14 4
> 15 .
>
> What I want is the following:
>
> OBS X
> 1 1
> 2 1
> 3 1
> 4 2
> 5 2
> 6 2
> 7 2
> 8 3
> 9 3
> 10 3
> 11 3
> 12 3
> 13 3
> 14 4
> 15 4
>
> I want the missing values replaced by the previous
> non-missing value. I thought that:
<snip>
> I'm thinking about
> arrays and have read Ron Cody's array tutorials,
> but nothing is jumping out at me.
>
> Any advice?
> Much thanks.
Jennifer,
There is a _very_ simple way to achieve this, as follows:
DATA ONE (drop=tempvar);
SET MYDATA;
retain tempvar ;
IF X = . THEN x = tempvar ;
else tempvar = x ;
run;
I hope this is clear and self-explanatory - if you don't understand it
then I suggest you read up on the RETAIN statement.
Bruce
|