Help using Base SAS procedures

Keeping 15 min

Reply
Regular Contributor
Posts: 240

Keeping 15 min

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

Super User
Posts: 17,750

Re: Keeping 15 min

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?
Regular Contributor
Posts: 240

Re: Keeping 15 min

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 

Super User
Posts: 9,662

Re: Keeping 15 min

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;

 

 

Ask a Question
Discussion stats
  • 3 replies
  • 283 views
  • 0 likes
  • 3 in conversation