|
data a;
length name $15.;
input name $ date1 $10. time1 $ date2 $10. time2 $ ;
datalines;
XiaoMing 2013/05/23 09:08:22 2013/05/23 11:08:22
XiaoMing 2013/05/24 04:03:12 2013/05/24 16:25:01
XiaoMing 2013/05/26 19:08:22 2013/05/26 22:52:11
XiaoMing 2013/05/27 02:35:22 2013/05/27 09:08:22
XiaoMing 2013/06/26 02:35:22 2013/06/27 09:08:22
XiaoHong 2013/05/21 01:56:21 2013/05/23 08:08:08
XiaoHong 2013/05/23 23:08:22 2013/05/24 02:01:11
XiaoHong 2013/06/23 23:08:22 2013/06/24 02:01:11
XiaoZhang 2013/01/01 15:05:25 2013/01/01 24:00:00
XiaoZhang 2013/06/01 15:05:25 2013/06/01 24:00:00
XiaoLu 2013/05/03 02:03:26 2013/05/03 09:11:55
XiaoLu 2013/06/03 02:03:26 2013/06/03 09:11:55
XiaoLu 2013/06/23 02:03:42 2013/06/29 12:18:56
XiaoJiu 2013/06/01 15:05:25 2013/06/01 24:00:00
;
run;
data a1;
set a;
indate1=input(date1,yymmdd10.);
intime=put(indate1,date9.)||' '||time1;
intime1=input(intime,DATETIME18.);
outdate1=input(date2,yymmdd10.);
outtime=put(outdate1,date9.)||' '||time2;
outtime1=input(outtime,DATETIME18.);
usetime=outtime1-intime1;
run;
proc sort data=a1 out=a2;
by name;
run;
data a3;
set a2;
by name;
retain x;
if first.name then x=0;
x+1;
run;
data a4;
set a2;
by name;
retain y;
if first.name then y=0;
y+1;
if last.name then output;
keep name y;
run;
data fa;
merge a3 a4;
by name;
run;
data b1;
set fa;
if y=1 then delete;
if dif(x)>0 and dif(indate1)>30 then delete;
run;
data b2;
set fa(keep=name date1 indate1 x);
mouth=substr(date1,6,2);
demouth=lag(mouth);
if x=1 then demouth=.;
if mouth-demouth>0 and dif(indate1)>30 then mark=1;
else if mouth =06 and demouth=. then mark=1;
else mark=0;
drop mouth demouth x;
run;
data fa1;
set fa;
indate='2013/05/01';
outdate='2013/06/01';
if indate<date1<outdate then output;
run;
data b3;
set fa1;
by name;
retain worktime;
if first.name then worktime=0;
worktime=worktime+usetime;
if last.name then output;
run;
B1 B2 B3是结果
|