Here's one way:
data want (keep=travelerid orig dest traveltime);
set have;
retain cumtime 0 RealOrig " ";
if orig_stop='Y' then do;
cumtime=0;
RealOrig=Orig;
end;
If dest_stop = 'N' then cumtime= sum(cumtime,traveltime,time_spent_at_dest);
if dest_stop='Y' then do;
cumtime= sum(cumtime,traveltime);
orig= RealOrig;
TravelTime=CumTime;
output;
end;
run;
This assumes well formed data: No traveller id starting with something for Orig_stop other than 'Y', last traveller Id is Dest_stop='Y'.
If you travell id doesn't behave that way then you'll need to make some decisions about how to handle the exceptions. They might be amenable to BY Travellerid processing with First and Last but no promises.
... View more