I'm new to SAS and I'm trying to automate the process of calling a macro with different parameters.
Here's the macro I want to call.
%macro expo(month, year);
data policy_&month&year;
set lastpol2;
by policy_no;
drop uwmonth;
accidentmonth = &month&year;
run;
%mend;
I need to call this macro for every month and every year since 2016, so the current method is to simply call the macro multiple times.
%expo(1,2016);
%expo(2,2016);
%expo(3,2016);
%expo(4,2016);
%expo(5,2016);
...
...
%expo(10,2021);
%expo(11,2021);
%expo(12,2021);
Instead of having this long list, I want to create a loop that gets the current year and iterates over every month for each year. My approach for this is by writing a macro to call the other macro multiple times with different parameters, here's my attempt so far.
%macro create_policies();
%let current_year = year(input("&sysdate9",date9.));
%let policy_start_year = 2016;
%if policy_start_year <= current_year %then
%do i = 1 %to 12;
%expo(&i, &policy_start_year);
%end;
%let policy_start_year = &policy_start_year + 1;
run;
%mend;
%create_policies()
So I'm trying to loop through 1 to 12 and call the macro each time using number in the loop. After the index 12 has been reached, I want the year to change to the next year and for the process to repeat until it's finished the current year.
Any help or pointers would be great.
Thanks.