You could compare two daily datasets at a time, but that would mean processing most of the datasets twice, once as the "before" date, and once as the "after".
But if each of the datasets are sorted by TKT, then you could process all of the datasets in a single pass. Something like (I have changed the daily dataset names to DATA_20250401, DATA_20250402, ... DATA_20250430):
data want;
set data_202504: ;
by tkt descending date;
if first.tkt=0 and dif(date)^=-1 then output;
else if first.tkt=1 and date^='30apr2025'd then output;
run;
If the data are not sorted by TKT and if sorting would be expensive, then read the datasets in reverse chronological order. You could use two hash objects to hold current and next daily data (NEXTDAY in the code below). If an incoming observation has a TKT not found in the NEXTDAY object, then output it. At the end of each day, clear the NEXTDAY object and copy the CURRDAY data into it, in preparation for new current date.
data want;
set data_202504: ;
by descending date;
if _n_=1 then do;
declare hash currday();
currday.definekey('tkt');
currday.definedata('tkt','date');
currday.definedone();
declare hiter i ('currday');
declare hash nextday();
nextday.definekey('tkt');
nextday.definedata('tkt','date');
nextday.definedone();
end;
if date='30apr2025'd then do;
nextday.add();
return;
end;
currday.add();
if nextday.check()^=0 then output;
if last.date then do;
/*Replace NEXTDAY with CURRDAY hash object */
nextday.clear();
do while (i.next()=0);
nextday.add();
end;
currday.clear();
end;
run;
Note these programs assume there are no duplicate TKT values within each daily dataset.
... View more