Date: Tue, 17 Mar 2009 14:51:46 -0400
Reply-To: Akshaya <akshaya.nathilvar@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Akshaya <akshaya.nathilvar@GMAIL.COM>
Subject: Re: how to substitute a missing value with previous record?
In-Reply-To: <200903171839.n2HAmaGR026054@malibu.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1
I posted DOW solution(adopted from previous Data _null_'s post) earlier.
That will fill the consecutive missing spots from previous non-missing
value.
Data want;
do until(eof);
set have end=eof;
locf=ifn(missing(score),locf,score);
output;
end;
Run;
On Tue, Mar 17, 2009 at 2:39 PM, Ya Huang <ya.huang@amylin.com> wrote:
> This won't work if you have more than one consecutive missing:
>
> data xx;
> input x $ value;
> cards;
> 3/17/2009 2
> 3/18/2009 3
> 3/19/2009 7
> 3/20/2009 .
> 3/21/2009 .
> 3/22/2009 4
> 3/23/2009 9
> ;
>
> data better;
> drop previous;
> previous = value ;
> set xx ;
> value1 = coalesce( value, previous);
> run;
>
> proc print;
> run;
>
> value x value1
>
> 2 3/17/200 2
> 3 3/18/200 3
> 7 3/19/200 7
> . 3/20/200 7
> . 3/21/200 .
> 4 3/22/200 4
> 9 3/23/200 9
>
> the missing in value1 is expected to be 7.
>
> On Tue, 17 Mar 2009 13:53:34 -0400, Peter Crawford
> <peter.crawford@BLUEYONDER.CO.UK> wrote:
>
> >i like the smallest.
> >data better ;
> > drop previous;
> > previous = value ;
> > set original ;
> > value= coalesce( value, previous);
> >run;
> >
> >
> >On Tue, 17 Mar 2009 08:20:56 -0700, Yi Zhang <zhangyiosu@GMAIL.COM>
> wrote:
> >
> >>hi guys,
> >>I has a time series data with some missing values. I want to
> >>substitute the missing value with the value in the last time. For
> >>example, I have
> >>3/17/2009 2
> >>3/18/2009 3
> >>3/19/2009 7
> >>3/20/2009 3
> >>3/21/2009 missing
> >>3/22/2009 4
> >>3/23/2009 9
> >>
> >>I want to have
> >>3/17/2009 2
> >>3/18/2009 3
> >>3/19/2009 7
> >>3/20/2009 3
> >>3/21/2009 3
> >>3/22/2009 4
> >>3/23/2009 9
> >>
> >>Any idea how to do this in a DATE STEP?
>
--
AkshayA!
|