Sorry for the hassle, but I just notice the solution gives the wrong fixed_time (every 2 seconds relative to 09:12 instead of 09:11). I changed the code a bit by subtracting 1 from the fixed_time and fixed_opentime variables (I haven't yet fully understand how the code works), so it seems to give the required result: Thanks again, SK data want (drop=nxt_: _: fixed_opentime); /* Read the openflag trade, followed by all trades (include 2nd read of openflag trade*/ set trades (where=(openflag=1) in=optrade) trades (in=alltrades) end=end_of_tr; /*by ticker; */ if optrade then do; /* if optrade set opentime and delete this record ... it will be read again*/ opentime=timestamp; fixed_opentime=round(1+opentime,2)-1; _open_minus_60=fixed_opentime-60; /*Minimum acceptable fixed_time*/ _open_plus_60=fixed_opentime+60; /*Maximum acceptable fixed_time*/ delete; end; retain opentime fixed_opentime _open_minus_60 _open_plus_60; format opentime fixed_opentime _open_minus_60 _open_plus_60 time8.0; /* Read ahead one record to get next fixed_time*/ if end_of_tr=0 then set trades (firstobs=2 keep=timestamp rename=(timestamp=nxt_timestamp)); else nxt_timestamp=_open_plus_60+2; fixed_time=round(1+timestamp,2)-1; nxt_fixed_time=round(1+nxt_timestamp,2); format fixed_time nxt_fixed_time time8.0; if nxt_fixed_time=fixed_time then delete; /*keep only final rec for each fixed_time*/ if nxt_fixed_time<_open_minus_60 then delete; /*drop records that are too early*/ if fixed_time>_open_plus_60 then stop; /*replace "stop" by "delete" if sorted by ticker/timestamp */ do fixed_time=max(fixed_time,_open_minus_60) to min(nxt_fixed_time-2,_open_plus_60) by 2; output; end; run;
... View more