data tm;
length id $ 12;
input date:yymmdd10. id $ name $ @@;
cards;
2012-5-31 PID000100282 马梅
2012-6-1 PID000100282 马梅
2012-6-2 PID000100282 马梅
2014-7-15 PID000100445 朱文
2012-10-30 PID000101056 骆超
2013-3-30 PID000101493 许荣
2013-4-6 PID000101493 许荣
2013-4-8 PID000101493 许荣
2013-4-9 PID000101493 许荣
;
run;
*查询连续3天及以上的数据;
proc sort data=tm;
by id date;
run;
data over3;
set tm;
by id date;
y=dif(date);
if first.id then do;
x=0; end;
else x=dif(date);
*format date yymmdd10.;
run;
proc print;
run;
/***********
我的思路是,按id分组
在组内第一个观测x=0,组内第二个观测x=第一个date-第二个date
通过x的值是不是=1 来判断数据是否连续
不明白为什么,y=dif(date)正常,x=dif(date)无效???
此外,请问解决这种连续日期问题的算法,越多越好!谢谢
***********/