If possible using a concatenated libref as suggested by @ChrisNZ will simplify greatly and reduce the need for the recursive macro. Duplicate file names in subfolders could be problematic.
Assuming that you cannot change the naming convention of the files, unfortunately an all too common reality, the following macro will delete a file from a provided location (fileref).
%macro Fdel(fileref=, filename=);
%local dd yy mon filedate rc tref;
%let tref=temref;
%* assume file name is in the form of:
%* xxxdd_YYYYmon.sas7bdat;
%let dd = %substr(&filename,4,2);
%let yy = %substr(&filename,7,4);
%let mon = %substr(&filename,11,3);
%let filedate = %eval(%sysfunc(inputn(&mon&yy,monyy7.)) + &dd - 1);
%if %sysfunc(intnx(month,&filedate,24,s)) lt %sysfunc(date()) %then %do;
%let rc = %sysfunc(filename(tref,%sysfunc(pathname(&fileref))\&filename));
%let rc = %sysfunc(fdelete(temref));
%let rc = %sysfunc(filename(temref));
%end;
%mend fdel;
filename myloc 'c:\temp';
%fdel(fileref=myloc, filename= ab002_2015apr.sas7bdat)
%fdel(fileref=myloc, filename= gh005_2015mar.sas7bdat)
%fdel(fileref=myloc, filename= gh015_2016nov.sas7bdat)
I have made some assumptions about your file naming conventions - adjust as needed.
... View more