data _null_;
infile "R:\myData.txt" truncover firstobs=5;
file "R:\new.txt" lrecl=500;
input id1 $ 1 id2 $ 4-5 id3 $ 1-3 id4 $ 9-9 id5 $ 2-4 fd $ 1-200;
t1=lag(fd);
if id3 in ("Sun","Mon","Tue","Wed","Fri","Sat","Thu") then put fd;
if id1 in ('0','1','2','3','4','5','6','7','8','9') then put fd;
if id5="Add" then put@1 "A" @2 fd;
if id4="M" then put @1 t1 @110 fd;
run;
data e f;
infile "R:\new.txt" truncover;
retain name;
retain EmployeeID;
input lm $ 1-1 @;
if lm in ("0","1") then input @1 EmployeeID :6. name $ 7-30;
name=compress(name,"0");
name=compress(name,"1");
name=compress(name," ");
if lm in ("S","M","T","W","F") then do;input Day $ 1-3 Date $ 4-8 In1 $ 11-15 Out1 $ 42-46 ID1 $ 50 In2 $ 52-56 Out2 $ 83-87 Totals 91-95 TotalsCum 99-104 ID2 $ 110 In3 $ 112-116 Out3 $ 143-147 Totals2 192-196 TotalsCum2 200-205;output e;end;
if lm="A" then do;input Date $ 20-24 Comments1 $ 2-10 CommentTime1 $ 26-30; output f;end;
run;
proc sort data=f; by employeeid date;run;
data g;
set f;
by employeeid date;
t1= lag(Comments1); t2= lag(CommentTime1) ;
if EmployeeID=lag(EmployeeID) and Date=Lag(date) then do c=1;comments2=t1; CommentTime2=t2;put comments2= CommentTime2= EmployeeID= date=;end;
run;
proc sql;
create table m as select employeeid,date,count(*) as cnt from g group by employeeid, date ;
quit;
data n1;
merge g m;
by employeeid date;
run;
proc sort data=n1; by employeeid date; run;
data n2(keep=name EmployeeID Date Comments1 CommentTime1 Comments2 CommentTime2);
set n1;
by employeeid date;
if first.Date=1 and cnt>1 then delete;
run;
proc sort data=e; by employeeid date; run;
proc sql;
create table t1 as select employeeid,date,count(*) as cnt from e group by employeeid, date ;
quit;
data t2;
merge e t1;
by employeeid date;
run;
proc sort data=t2; by employeeid date; run;
data i(drop=lm cnt Totals2 TotalsCum2) ;
set t2;
by employeeid date;
if Totals2 ne . and Totals eq . then Totals=Totals2;
if TotalsCum2 ne . and TotalsCum eq . then TotalsCum=TotalsCum2;
if first.Date and cnt>1 then delete;
run;