The first macro below I got from SAS website. I want to eliminate the %let start=, %let end=, and %let dif=, statements and just have the INTCK calculation done in the "%do i = 0 %to" line. If I make substitutions one at a time, the code works fine up until I attempt to substitute "%let start =" piece. If you try to run the code below, the first 3 will work but the last one will not.
Please help me understand why the last code will not work. Thanks in advance.
* THIS IS THE ORIGINAL FILE FROM THE SUPPORT.SAS WEBSITE;
%macro date_loop(start,end);
%let start=%sysfunc(inputn(&start,anydtdte9.));
%let end=%sysfunc(inputn(&end,anydtdte9.));
%let dif=%sysfunc(intck(month,&start,&end));
%do i=0 %to &dif;
%let date=%sysfunc(intnx(month,&start,&i,b),date9.);
%put &date;
%end;
%mend date_loop;
%date_loop(01jul2015,01feb2016);
* THIS DOES THE &dif CALCULATION IN THE DO LOOP;
%macro date_loop(start,end);
%let start=%sysfunc(inputn(&start,anydtdte9.));
%let end=%sysfunc(inputn(&end,anydtdte9.));
%do i=0 %to %sysfunc(intck(month,&start,&end));
%let date=%sysfunc(intnx(month,&start,&i,b),date9.);
%put &date;
%end;
%mend date_loop;
* THIS SUBSTITUTES THE "%let end=" LINE INTO THE 3RD ARGUMENT OF THE INTCK FUNCTION;
%macro date_loop(start,end);
%let start=%sysfunc(inputn(&start,anydtdte9.));
%do i=0 %to %sysfunc(intck(month,&start,%sysfunc(inputn(&end,anydtdte9.))));
%let date=%sysfunc(intnx(month,&start,&i,b),date9.);
%put &date;
%end;
%mend date_loop;
* THIS SUBSTITUTES THE "%let start=" LINE INTO THE 2RD ARGUMENT OF THE INTCK FUNCTION;
%macro date_loop(start,end);
%do i=0 %to %sysfunc(intck(month,%sysfunc(inputn(&start,anydtdte9.)),%sysfunc(inputn(&end,anydtdte9.))));
%let date=%sysfunc(intnx(month,&start,&i,b),date9.);
%put &date;
%end;
%mend date_loop;
... View more