Suppose that I have a library save which contains daily files thefile_dly_yyyymmdd,
e.g. save.thefile_dly_20150831, save.thefile_dly_20150901, ... , save.thefile_dly_20210731.
I want to perform some manipulation on the historical data in this library, however, I only want to extract the files between a specific date, and also only want to keep the file which corresponds to the last file for each month, e.g. I want to extract save.thefile_dly_20150831, save.thefile_dly_20150930, save.thefile_dly_20151031, etc.
Something like the following.
%macro loop_through(start,end);
%do i = &start. %to &end.;
%if %sysunc(exist(SAVE.THEFILE_DLY_&i.)) %then %do;
/* Do some data processing on the file */
%end;
%end;
%mend;
%loop_though(20150831,20210731);
The problem is that the abovementioned code will loop through every single integer between 20150831 and 20210731, which is not optimal, and also, it will process every single file that exists for the month, and not just the file corresponding to the last day of each month.
How can I adjust? Any advice will be appreciated.