问题
I want to have a sas macro loop by even years, so the do loop would jump from 2006 to 2008 to 2010...all the way to 2018 and not from 2006 to 2007.
When I do a %by = 2, SAS doesn't work and gives me an error message. What is the best solution?
I have the following Code:
%macro import;
%do I = 2006 %to 2018;
data BTI&I;
set edited.Bti_&I;
year=&I;
run;
%end;
%mend import;
%import;
回答1:
Add the %by 2
keyword to increment intervals of 2. I would also recommend passing the start and end years as parameters to your function and give defaults values of 2006 and 2018.
%macro import(start=2006, end=2018);
%do I = &start. %to &end. %by 2;
data BTI&I;
set edited.Bti_&I;
year=&I;
run;
%end;
%mend import;
%import;
Usage:
%import();
which will use the default values 2006 & 2018%import(start=2009, end=2018);
specify the date range you want to use
来源:https://stackoverflow.com/questions/49660035/sas-macro-do-loop