BookmarkSubscribeRSS Feed
BETO
Fluorite | Level 6

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;
How would it look like if I wanted to keep everything within 15min? ... If it was greater than 15 min drop.. Table one columns would be machine time date. Table 2 machine start date end date duration time

3 REPLIES 3
Reeza
Super User
What's previous? Say record 1, you have everything within 15 mins. Record 3 is within 15 mins of Record 1. Record 5 is within 15 mins of Record 1 and 3.

How do you want the output to look?
BETO
Fluorite | Level 6

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;

 

 

instead of of removing them I wanted to keep 15 min or less an remove 15 min greater 

Ksharp
Super User

You did not post the output yet ?

 

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
;
data t;
set t1 t2;
dt = dhms(date,0,0,time);
format dt datetime19. date date9. time time8.;
run;
proc sort data=t; by machine dt; run;
data want;
 set t;
 if Machine eq lag(Machine) and dif(dt) le '00:15:00't;
run;

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 769 views
  • 0 likes
  • 3 in conversation