Date: Mon, 9 Jul 2012 14:33:33 -0500
Reply-To: "Data _null_;" <iebupdte@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Data _null_;" <iebupdte@GMAIL.COM>
Subject: Re: How to retain?
Content-Type: text/plain; charset=ISO-8859-1
I believe this accomplished the task. I think you might call this
step interpolation or LOCF.
Notice I made them missing pattern a bit more complex but that your
original example but it still works the same way. Your NEW is now the
dummy KEY with the same value on all obs. Update usually outputs on
LAST. KEY that's why we need the OUTPUT statement.
retain new +1;
if _n_ in(2,3,4,5,8,9,12,16,17,18)
then call missing (of name age weight);
else call missing(of sex height);
update try(obs=0) try;
On 7/9/12, Titaan <email@example.com> wrote:
> Dear Users,
> I am having difficulty in getting a flexible code. I have a dataset with
> lot of missing values. I need to fill those missing values with previous
> populated ones. I can use multiple lag statements to fill them. But I have
> a huge file and the missing records vary from 1 to at least 15. I want to
> get a dynamic code that takes care every thing. I tried retain/lag/do
> until/while. But missing something. I am not getting a correct one. Your
> suggestions are welcome.
> Below is a test data.
> data try;
> set sashelp.class;
> new +1;
> if new in (2,3,4,5,8,9,12,16,17,18) then call missing (of name --
> After running this code, my data will look like that. I need to fill the
> 1st row data in 2,3,4,5 rows. Like that, if I have any missing rows, I
> need to fill them with the previous non missing row data.