@Red781:
First, note that you sample input doesn't match your sample output in terms of Datetime; I assume that the figures shown in the output are correct. Second, you need some kind of memory table to store your datetime and price values for backtracking while applying your datetime range criteria. Below, I've chosen a hash table; but it can be an array as well.
data have ;
input geoloc $ itemnum datetime :anydtdtm19. price ;
format datetime e8601dt. ;
cards;
Miami 1 2019-05-24:09:21:55.000 2.00
Miami 2 2019-05-24:09:21:55.000 2.49
Miami 3 2019-05-24:09:22:30.000 0.99
Miami 4 2019-05-24:09:23:27.000 0.49
Dallas 5 2019-05-24:09:23:13.000 2.50
Dallas 6 2019-05-24:09:23:42.000 4.00
Dallas 7 2019-05-24:09:26:05.000 7.00
Dallas 8 2019-05-24:09:26:56.000 3.99
Dallas 9 2019-05-24:09:27:02.000 0.89
;
run ;
data v (drop = _:) / view = v ;
if _n_ = 1 then do ;
dcl hash h (dataset:"have(rename=(datetime=_d price=_p))", ordered:"d") ;
h.definekey ("geoloc", "itemnum") ;
h.definedata ("geoloc", "itemnum", "_d", "_p") ;
h.definedone () ;
dcl hiter hi ("h") ;
call missing (_d, _p) ;
end ;
set have ;
hi.setcur() ;
_g = geoloc ;
do totalprice = _p by 0 while (hi.next() = 0 and _g = geoloc and datetime < _d + 60 ) ;
totalprice + _p ;
end ;
run ;
proc rank data = v out = want ;
var totalprice ;
ranks Volume ;
run ;
Kind regards
Paul D.
... View more