The data step creating have has errors: unclosed quotes and a run in the middle of the step. The format statement is missing, too.
Saving the first values of police_effective_date and police_end_date in retained variables and using them to set flag when the data step reached to last obs for police seem to create what you want:
data want;
set have;
by police;
length
flag $ 10
first_eff_date first_end_date 8
;
retain first_:;
if first.police then do;
first_eff_date = police_effective_date;
first_end_date = police_end_date;
end;
if last.police then do;
if police_end_date > first_end_date then do;
if police_effective_date = first_eff_date then flag = "EXTENDED";
if police_effective_date > first_eff_date then flag = "SHIFTED";
end;
end;
drop first_:;
run;
Assuming the data is sorted by police and end.
... View more