Convert your measurement readings from time points to intervals. Then you can merge the alarm times with the intervals. I changed the time of the second alarm (and the label) so that it would match a SPEED value. data alarms ; infile cards dsd dlm='|' truncover ; informat timestamp anydtdtm. ; format timestamp datetime24.2; length alarm $20; input timestamp alarm; cards; 3/02/2014 16:03:23.0|Alarm 1 3/02/2014 18:01:02.0|Alarm 2 run; data values ; infile cards dsd dlm='|' truncover ; informat timestamp anydtdtm. ; format timestamp datetime24.2; length position $20; input timestamp position value; cards; 3/02/2014 16:02:34.1|Position|22.34 3/02/2014 16:02:34.3|Position|22.37 3/02/2014 16:03:02.7|Speed|83 3/02/2014 16:04:01.6|Position|22.39 3/02/2014 16:04:03.2|Speed|77 3/02/2014 16:07:29.0|Position|22.48 run; proc sort ; by position descending timestamp ; run; data ranges ; set values ; by position descending timestamp ; start=timestamp; end = lag(timestamp); if first.position then end = .; format start end datetime24.2; keep position value start end run; proc sql ; create table want as select a.alarm,a.timestamp as alarm_time, b.* from alarms a left join ranges b on a.timestamp >= b.start and (a.timestamp < b.end or b.end is null) order by 1,2 ; quit; proc print; run; Alarm 1|02MAR2014:16:03:23.00|Position|22.37|02MAR2014:16:02:34.30|02MAR2014:16:04:01.60 Alarm 1|02MAR2014:16:03:23.00|Speed|83|02MAR2014:16:03:02.70|02MAR2014:16:04:03.20 Alarm 2|02MAR2014:18:01:02.00|Position|22.48|02MAR2014:16:07:29.00| Alarm 2|02MAR2014:18:01:02.00|Speed|77|02MAR2014:16:04:03.20|
... View more