You start with:
This first macro should be extracting datasets that have a date field in their name. E.g. 201803. The macro should loop through quarterly data.
So, show the EXACT names of the data sets, not the date value, the entire data set names that you expect to extract for the given parameters in your example.
Then explain why if you want quarterly data sets the loop in Loopback is hard coded to get 12 monthly output "dates". The logic quite escapes me. Are the sets monthly or quarterly. It may be you are confusing us with poor word order.
Please don't leave stubs of like that partial Proc sql.
proc sql;
----------------
It doesn't explain anything of the logic if this is supposed to build the set DATASETS used in the Merge statement is a likely problem.
And why does that data step
data val;
merge datasets;
run;
"merge" a single data set? and hardcoded? It never changes based on any of the macro code so I don't see where anything is done.
And the loops, as is very easily seen in the log as generated by your %put statements includes the same months multiple times.
It might help to show the non-macro code that you used to develop the logic before attempting to create the macro version.
... View more