Hello,
Here is a generic macro that loop over month between a start date and an end date.
%macro loop_month(start, end, action);
/* action : name of a macro that takes a date value as parameter */
%let MAXITER=10;
data _NULL_;
start=input("&start.", anydtdte.);
end=input("&end.", anydtdte.);
curr=start;
do while (curr<=end and i<&MAXITER.);
call execute(cats('%nrstr(%&action.)(', curr, ')'));
curr=intnx("month", curr, 1);
i+1;
end;
run;
%mend loop_month;
%macro mymacro(date);
data _NULL_;
date=&date.;
call symputx('mmyy', put(date, monyy5.));
call symputx("first_day_of_month", intnx("month", date, 0, "b"));
call symputx("last_day_of_month", intnx("month", date, 0, "e"));
run;
data test_&mmyy.;
set sashelp.class;
run;
proc sql noprint;
CREATE TABLE dates_&mmyy. AS
SELECT date
FROM dates
WHERE date BETWEEN &first_day_of_month. AND &last_day_of_month.
;
quit;
%mend mymacro;
data dates;
input date date9.;
cards;
25Jan2017
30Nov18
02Feb2019
20Aug2019
01Jan2020
;
quit;
%loop_month(01Nov2018, 01May2019, mymacro)
... View more