Sort of what @Tom started with. This code takes the start date and end date and loops the number of months there is between the dates. In each loop you will have to add the four SQL queries with the correct month and year. %macro onePass(Year, Month);
*Do one of the passes of your four SQL;
*No code for easier reading of a solution;
%if &month < 10 %then %let month=0&month; *Make sure you have a leading 0 on the month;
%put &=year &=month; * Use &year and &month in your code instead of the static years and month.
%mend onePass;
%macro dateLoop(Beg_YYYY=2018, Beg_MM=12,End_YYYY=2019,End_MM=02,Val_YYYY=2019,Val_MM=02);
%let startDate = %sysfunc(mdy(&Beg_MM,01,&Beg_YYYY));
%let endDate = %sysfunc(mdy(&End_MM,01,&End_YYYY));
%let NumberOfMonths = %sysfunc(intck(month,&startDate,&endDate));
%do _i=1 %to &NumberOfMonths +1; *We have to add one month.;
%let date=%sysfunc(intnx(month,&startDate,&_i));
%let month =%sysfunc(month(&date));
%let year =%sysfunc(year(&date));
%onePass(&year, &month);
%end;
%mend dateLoop;
%dateLoop(Beg_YYYY=2018, Beg_MM=12,End_YYYY=2018,End_MM=12,Val_YYYY=2019,Val_MM=02);
... View more