Supposing your macro variable &reptmon contains month and year in the format MMYYYY, this works without macro logic, it only uses macro variables to hand values over from one step to the next:
data _null_;
last_month = input("01&reptmon.",ddmmyy8.);
length dsn $41 all_datasets $1301;
/* maximum length needed: 32 bytes for datasetname, 8 for library, 1 for dot */
do date = last_month to intnx('month',last_month,0,'e');
dsn = 'save.scb_welcome_call_list_' !! putn(date,ddmmyyn8.);
if exist(dsn) then all_datasets = catx(' ',trim(all_datasets),dsn);
end;
call symput('all_datasets',trim(all_datasets));
run;
data save.scb_welcome_call_list_&reptmon;
set &all_datasets;
run;
Instead of a series of appends, you get one data step that does the concatenation; also note that this procedure can be run repeatedly during a month, always resulting in correct values up-to-date.
... View more