funnyxuke 发表于 2010-2-5 05:03 
this should work
option missing=.;
data test;
input year code a;
datalines;
1995 1 90
1996 1 .
1997 1 .
1998 1 100
1999 1 120
1995 2 70
1996 2 .
1997 2 .
1998 2 40
1999 2 .
;
run;
proc sort data=test;
by code year;
run;
data new (drop=c);
retain b .;
set test;
by code year;
c=lag(a);
if c ne . then b=c;
if first.code then b=.;
run;
proc print data=new;
run;
1# walkinggirl
The new data logic can be simplied as,
data new ;
retain b .;
set test;
by code year;
if first.code then b=.;
output;
if a ne . then b=a;
run;