Hi I have a 2 tables that
Machine. Time. Date
A1. 15:35:35 11/07/15
A2 10:59:06 11/04/15
A1. 15:42:23. 11/07/15
Table2
Machine. Time. Date
A1. 15:38:35 11/07/15
A2 10:55:06 11/04/15
A3 15:45:23. 11/07/15
I need to look into both tables an keep the entries that are in one table an not the other.if there are 2 entries that have same date ,same machine an the time falls between 15 min of each table exclude one of the 2...the output shoult look like this
Machine. Time. Date
A3 15:45:23. 11/07/15.
A1. 15:35:35 11/07/15
A2. 10:55:06 11/04/15
I suggest to use datetimes. It makes the code simpler and allows matching times just before and after midnight :
data t1;
input Machine $ Time :time8. Date :mmddyy8.;
datalines;
A1 15:35:35 11/07/15
A2 10:59:06 11/04/15
A1 15:42:23 11/07/15
;
data t2;
input Machine $ Time :time8. Date :mmddyy8.;
datalines;
A1 15:38:35 11/07/15
A2 10:55:06 11/04/15
A3 15:45:23 11/07/15
;
/* Concatenate the tables, create datetimes */
data t;
set t1 t2;
dt = dhms(date, hour(time), minute(time), second(time));
format dt datetime19. date date9. time time8.;
run;
proc sort data=t; by machine dt; run;
/* Drop records that are less than 15 min. from previous */
data want;
do until(last.machine);
set t; by machine;
if dt - '00:15:00't > lastDT then do;
output;
lastDT = dt;
end;
end;
drop lastDT;
run;
proc print data=want noobs; run;
I suggest to use datetimes. It makes the code simpler and allows matching times just before and after midnight :
data t1;
input Machine $ Time :time8. Date :mmddyy8.;
datalines;
A1 15:35:35 11/07/15
A2 10:59:06 11/04/15
A1 15:42:23 11/07/15
;
data t2;
input Machine $ Time :time8. Date :mmddyy8.;
datalines;
A1 15:38:35 11/07/15
A2 10:55:06 11/04/15
A3 15:45:23 11/07/15
;
/* Concatenate the tables, create datetimes */
data t;
set t1 t2;
dt = dhms(date, hour(time), minute(time), second(time));
format dt datetime19. date date9. time time8.;
run;
proc sort data=t; by machine dt; run;
/* Drop records that are less than 15 min. from previous */
data want;
do until(last.machine);
set t; by machine;
if dt - '00:15:00't > lastDT then do;
output;
lastDT = dt;
end;
end;
drop lastDT;
run;
proc print data=want noobs; run;
Post as a new question with example data and expected output.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.