|
Re: 连续数据的个数计算
[code:2vodcc79]
data v ;
input Reporter Partner Product year ;
cards;
1 003 30303 1995
1 004 99284 1995
1 003 30303 1996
1 003 30303 1997
1 003 30303 2000
1 003 30303 2001
1 003 30303 2003
1 004 99284 1996
1 004 99284 1998
;
proc sort data=v;
by Reporter Partner Product year;
data v;
retain cnt _group 0 ;
set v;
_p1=lag(Reporter);
_p2=lag(Partner);
_p3=lag(Product);
_y=lag(year);
if _p1=Reporter and _p2=Partner and _p3=Product and year-_y=1 then cnt+1;
else do;cnt=1;_group+1;end;
proc sql;
create table v(drop=_:) as select max(cnt) as cnt,*
from v
group by Reporter, Partner, Product ,_group
order by Reporter, Partner, Product ,year;
quit;
proc print;
run;
[/code:2vodcc79] |
|