Assuming that differences are calculated from ORDER = 1.
data have ;
input ID date:mmddyy10. time:time5. volume order ;
format date mmddyy10. time time5. datetime datetime22. ;
datetime = dhms(date,0,0,time) ;
cards ;
1234 1/2/2020 13:12 53.1 1
1234 1/2/2020 20:12 32.9 2
1234 1/3/2020 9:12 23.1 3
4522 3/2/2020 12:19 20.5 1
4522 3/2/2020 14:19 24.1 2
;
run ;
data want ;
set have ;
by id order ;
retain _d _v ;
drop _: ;
if first.id then
do ;
_v = volume ;
_d = datetime ;
end ;
else do ;
difference_hours = intck("hour",datetime,_d) ;
difference_volume = volume - _v ;
end ;
run ;
... View more