If I'm reading this correctly, you need to compare each datetime to a set of intervals (not just one interval). Your new variable should be 1 when the datetime falls within any of the intervals.
Here's a way to do that which creates your new variable as character "1" or "0". I'll mention more about that at the end.
Start by creating a format from your sets of intervals:
data intervals;
set dataset1 end=done;
start = start_time;
end = end_time;
label='1';
fmtname = 'interval';
output;
if done;
hlo='O';
label='0';
output;
run;
This creates a format that identifies all the intervals. (It will also double-check and give you and error if any of the intervals overlap so you can clean them up if necessary.) There is the possibility that you would use this statement instead:
end = end_time - 1;
Your comparison uses < end_time rather than <= end_time and I can't really tell if that is intentional or not.
At any rate, create a format to identify the intervals:
proc format cntlin=intervals;
run;
Then use the format to identify the individual activities:
data want;
set datasetA;
activity = put(datetime, interval.);
run;
Technically, if you really need your new variable as numeric instead of character "1" and "0", it would be possible to create an informat instead of a format by changing one of the variables within the INTERVALS data set.
... View more