Date: Mon, 19 May 2008 22:50:29 -0400
Reply-To: "Howard Schreier <hs AT dc-sug DOT org>"
<schreier.junk.mail@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Howard Schreier <hs AT dc-sug DOT org>"
<schreier.junk.mail@GMAIL.COM>
Subject: Re: Retain problem
On Mon, 19 May 2008 16:12:00 -0600, Jerry L Diebal <jdiebal@GMAIL.COM> wrote:
>I need to come up with data like in the 'Need' dataset below when starting
>out with data like in the 'Have' dataset:
>
>"Have" data shows an employee (empnum) and the operation (opnum) that they
>put labor (hrs) on. I need to 'backfill' that data to the previous records
>up to the point another employee has logged hours. The shift for that
>employee also needs to be backfilled. Once another employee is encountered
>the process starts over until reaching the first operation of each
>individual 'Ordernum'.
>
>The last operation for each 'Ordernum' may or may not be blank. If it is
>blank, it needs to remain that way since there are no succeeding operations
>to pickup empnum and shift from. I hope this explanation is intelligible.
>Thanks in advance.
>
>data have;
>infile datalines dsd;
>input empnum $ shift opnum ordernum hrs;
> datalines;
>,,10,1000111,1
>aaa,100,20,1000111,1
>,,30,1000111,1
>bbb,100,40,1000111,1
>,,50,1000111,1
>,,10,2000222,1
>ccc,100,20,2000222,1
>,,30,2000222,1
>ddd,200,40,2000222,1
>,,50,2000222,1
>;
>
>data need;
>infile datalines dsd;
>input empnum $ shift opnum ordernum hrs;
> datalines;
>aaa,100,10,1000111,1
>aaa,100,20,1000111,1
>bbb,100,30,1000111,1
>bbb,100,40,1000111,1
>,,50,1000111,1
>ccc,100,10,2000222,1
>ccc,100,20,2000222,1
>ddd,200,30,2000222,1
>ddd,200,40,2000222,1
>,,50,2000222,1
>;
Try this Double DoW:
data need;
do many = 1 by 1 until (not missing(shift) or last.ordernum);
set have;
by ordernum;
end;
next_empnum = empnum;
next_shift = shift ;
do m = 1 to many;
set have;
if missing(empnum) then empnum = next_empnum;
if missing(shift ) then shift = next_shift ;
output;
end;
drop many next_ : m;
run;
I think the test data set should be more demanding, with cases such as zero
or multiple omissions at the end of a group, and multiple omissions and
non-omissions at other points.
|