07-15-2014 11:59 AM
I have a macro that is looping through datafiles from different years for a proc mean. I want it to run with a different var statement depending on which year it is currently looping through. At the moment, my code looks like this:
%do i = &yrmin %to &yrmax;
%let yr = %substr(&i.,3,2);
proc means n mean median max data=&lib..&stem.&yr.;
%if 2000 <= &i <= 2011 %then
%else %if 2012 <= &i <= 2013 %then
vars other variables;
When I run the code, however, the program returns the following on years 2012 and 2013:
SYMBOLGEN: Macro variable I resolves to 2012
MLOGIC(VARCHECK): %IF condition 2000 <= &i <= 2011 is TRUE
It works if I replace the if conditions with &i = 2000 or &i = 2001 etc., but that can get pretty cumbersome. Is there a way to get this to resolve correctly, or am I stuck with the clunky way?
Need further help from the community? Please ask a new question.