Okay, it helps to see what you are working with. I think a macro is required here. You make things harder by using data set names that don't sort alphabetically, a data set named _20250401 for April 1 would at least sort properly, across months and within months, but maybe that doesn't even matter to produce the SAS code for this problem, but it might matter when you go ahead and try to use these datasets somehow.
%macro do_this;
%do date=%sysfunc(mdy(4,2,2025)) %to %sysfunc(mdy(4,30,2025));
%let previous_day=%eval(&date-1);
%let date1=%sysfunc(putn(&date,date9.));
%let previous_day1=%sysfunc(putn(&previous_day,date9.));
/* Remove leading zero from dates */
%if %substr(&date1,1,1)=0 %then %let date1=%substr(&date1,2);
%if %substr(&previous_day1,1,1)=0 %then %let previous_day=%substr(&previous_day1,2);
proc sql;
create table not_matching_&date1 as select distinct a.tkt
from data_&date1 a
left join data_&previous_day1 b on a.tkt=b.tkt where b.tktis null;
quit;
%end;
%mend;
%do_this
... View more