Here is a suggestion, but not sure what the point is of the dataset _duplicates_ in your example, since it gets overridden for each date in the list.
You could try this code, which works from the testdata dataset you create. If you want the customers who are duplicates, you can find them in the _AllDups_ table:
%macro check_duplicates(date_list, dataset);
proc sort data=&dataset.; by date customer; run;
data _AllDups_;
set &dataset.;
by date customer;
if first.customer then c=0;
c+1;
if last.customer and c>1 then output;
run;
%do i = 1 %to %sysfunc(countw(&date_list));
%let date = %scan(&date_list, &i);
%if %sysfunc(inputn(&date, yymmdd8.)) ne . %then %do;
data _null_;
dt=input("&date.", yymmdd8.);
put dt= date9.;
if _N_ = 1 then do;
length date 8;
declare hash stats(dataset:"AllDups");
stats.defineKey('date');
stats.defineDone();
end;
rc=stats.Check(key:dt);
if rc=0 then put "Dup found for &date.";
else put "No dup found for &date.";
run;
%end;
%end;
%mend;
%check_duplicates(20201231 20221231 20231231, testdata);
... View more