I'm posting here for the first time so forgive me if I doing it incorrectly. I'm a new sas user and am having trouble figuring out how to calculate a variable using a do loop. The data I'm looking at is household vehicle trip activity. The variables include Trip ID, Trip start time, Trip end time, and Household ID. What I'm trying to figure out is whether a trip's time overlaps with the other trip times of the same household. Here's an example of what I'm looking at. Trip ID Trip Start Time Trip End Time Household ID 1 8:00 17:00 999 2 9:30 9:45 999 3 10:00 18:00 999 My goal is to calculate the number of overlapping trips per household. In the final data-set each observation represents an unique household and the variable is the number of overlapping trips (in the case of the table above, 2) Does anyone know how I can use a do loop to calculate whether the end time in one trip (say trip 1) is greater than the start time in the other trips (trip 2 and trip 3)? I've never used a do loop before so any help would be greatly appreciated. I tried the syntax below but it didn't work the way I wanted it to. Plus it doesn't capture households with more than 2 trips. data travel_2 set travel by houseid overlap= .; if (first.endtime>last.starttime) then overlap=1; else overlap= 0; run;
... View more