Hi, thanks for your answer! I've created a macro around the original global statement and data step. And... it works, but only partly...! When I put begin month 08 and end month 10 for 2010 in the code (see below: %RUNYYMM(201008, 201010);), the program performs 3 steps, but only for month 10!
The strange thing is, the following statements situated in the code (the %put codes) DO generate the right dates in the log:
%PUT "YYYYMM IS " &YYYYMM;
%PUT "MMDDYYYY IS " &MMDDYYYY;
%PUT "THIS IS LOOP " &I;
For every of the 3 steps, the code above generates the right dates and the itteration of the steps --> in this case 3, because I've choosen for 2010-08 to 2010-10.
So the question now is... How can I get the month number and the year number from &YYYYMM (or &MMDDYYYY) and will this work?
THe code as it is now:
%MACRO RUNYYMM(BEG_YYMM,END_YYMM);
%LET BEG_YY = %EVAL(%SUBSTR(&BEG_YYMM,1,4) * 1);
%LET BEG_MM = %EVAL(%SUBSTR(&BEG_YYMM,5,2) * 1);
%LET END_YY = %EVAL(%SUBSTR(&END_YYMM,1,4) * 1);
%LET END_MM = %EVAL(%SUBSTR(&END_YYMM,5,2) * 1);
*GET ROUNDS OF THE LOOP;
%LET L=%EVAL((&END_YY-&BEG_YY)*12 + (&END_MM - &BEG_MM) + 1);
*GENERATE THE DATE CONSTANTS, THESE ARE GLOBAL VARIABLES;
%DO I = 1 %TO &L;
DATA _NULL_;
/* Ways to generate date MACRO VARIABLES*/
CALL SYMPUT('YYYYMM', PUT(INTNX('MONTH',MDY(&BEG_MM,1,&BEG_YY),&I - 1,'B'),YYMMN6.));
CALL SYMPUT('MMDDYYYY', "'"||PUT(INTNX('MONTH',MDY(&BEG_MM,1,&BEG_YY),&I - 1,'E'),MMDDYYN8.)||"'");
run;
%LET YEAR= %EVAL(%SUBSTR(&BEG_YYMM,1,4) * 1);
%LET MONTH = %EVAL(%SUBSTR(&BEG_YYMM,3,2) * 1);
*PUT THE DATE CONSTANTS IN THE LOG;
%PUT "YYYYMM IS " &YYYYMM;
%PUT "MMDDYYYY IS " &MMDDYYYY;
%PUT "THIS IS LOOP " &I;
*Original code;
libname x "D:\REPORTS\XLS\&YEAR\&MONTH\REPORT.XLS";
data _null_;
set x.'sheet1$'n;
file
"D:\REPORTS\XLS\&YEAR\&MONTH\REPORT.CSV" dsd;
put (_all_) (:);
run;
libname x clear;
%END
;
RUN;
%MEND
;
%RUNYYMM(201008, 201010);
... View more