This example is difficult to follow, and I'm not sure if there are other idiosyncrasies that need to be captured. This seems to output what you want, and I don't get any errors in my log.
data have;
infile datalines delimiter = ',';
input id $ location $ key_date :mmddyy10. key_time :time5. condition_a $ condition_b $ condition_c $;
format key_date mmddyy10. key_time time5.;
datalines;
1,1,1/1/2021,8:00 AM,Yes,Yes,Yes
2,1,1/1/2021,8:05 AM,Yes,Yes,Yes
3,2,1/1/2021,9:00 AM,No,Yes,No
4,2,1/1/2021,9:05 AM,Yes,Yes,Yes
5,2,1/1/2021,9:08 AM,Yes,Yes,Yes
6,3,1/2/2021,9:00 AM,Yes,Yes,Yes
7,3,1/2/2021,9:15 AM,Yes,Yes,No
8,3,1/2/2021,9:10 AM,Yes,Yes,Yes
;
run;
data have_2;
set have;
if condition_a = 'Yes' and condition_b = 'Yes' and condition_c = 'Yes' then yes = 1;
else yes = 0;
run;
proc sort data = have_2;
by location yes id;
run;
data want (drop = yes);
set have_2;
by location yes;
if first.yes and yes = 1 then first = 1;
else first = 0;
if last.yes and yes = 1then last = 1;
else last = 0;
run;
proc sort data = want;
by id location key_date;
run;
I would generally advise against naming variables that conflict with any SAS functions/automatic variables.
... View more