Re: How to do a reverse filling (missing observations)? #6

  • Follow


Hi,

The code I posted earlier rested on a GROUP variable, cnt, created as a part
of first data step. Thank you Chang for your excellent appreciation of my
use of double DoW. The use of UPDATE statement by you for this problem is
apt and concise.

Muthia Kachirayan



A solution without the use of group variable(cnt) follows:


data a;
input prodid custid year;
datalines;
1  1  .
2  1  .
3  1  1998
2  1  .
3  1  .
4  1  1999
4  2  .
5  2  .
6  2  1998
;
run;


data b(drop = yea y);
    set a;
    if year > . then do;
        y = year;
        do until (yea > .);
            set a (rename=(year = yea));
            year = y;
            output;
        end;
    end;
run;

Records are processed from top rather than from bottom and when a nonmissing
year is met it is saved and used in next do-loop. The renamed yea is used
for loop control.

The same logic can be used with point= option. The solution follows:

data b(drop = y count start);
start = 1;
do until(eof);
    set a;
    count + 1;
    if year > . then
    do;
        y = year;
        do p = start to count;
            set a point = p end = eof;
            year = y;
            output;
        end;
        start = count + 1;
    end;
end;
run;







On 4/26/07, Chang Chung <chang_y_chung@hotmail.com> wrote:
0
Reply muthia.kachirayan (702) 4/27/2007 4:38:55 PM


0 Replies
25 Views

(page loaded in 0.032 seconds)


Reply: