data raw;
input code date n;
datalines;
1 20010101 .
1 20010102 .
1 20010104 0
1 20010106 .
1 20010107 .
2 20010101 .
2 20010102 .
2 20010104 .
2 20010106 0
2 20010107 .
;
data out (drop=pos);
do _n_=1 by 1 until(last.code);
set raw;
by code;
if missing(n)=0 then pos=_n_;
end;
do _n_=1 to _n_;
set raw;
by code;
if first.code then m=-pos+1;
else m+1;
output;
end;
run;
参考:
http://www.pinggu.org/bbs/viewthread.php?tid=859941&page=2&from^^uid=64785#pid6541838