I am having an issue with a macro looping through some dates. I have 2 macros and they are structured as below: This first macro should be extracting datasets that have a date field in their name. E.g. 201803. The macro should loop through quarterly data. So starting at 201806 should move to 201809 and then 201812 datasets. %macro extract_all(start,end,interval);
%let start=%sysfunc(inputn(&start,yymmn6.));
%let end=%sysfunc(inputn(&end,yymmn6.));
%let dif=%sysfunc(intck(&interval.,&start,&end));
*-----------------------------------;
*Perform Extraction;
*-----------------------------------;
%do j=0 %to &dif;
%let date=%sysfunc(intnx(&interval.,&start,&j,e),yymmn6.);
%let date_d9=%sysfunc(intnx(month,%sysfunc(inputn(&date, yymmn6.)),0,E), date9.);
%put Observation_Date = &date.;
%put date_d9 = &date_d9.;
/* run all extraction macros*/
%Lookback(&date.);
%end;
%mend extract_all; The lookback macro extracts a variable over the last 12 months for the various quarterly datasets to be extracted. E.g. for 201806 the lookback macro should extract data 12 months prior (e.g. 201805, 201804, 201803, etc.) and then collate into one 1 final dataset for each quarter. The macro is partially defined below. I have left out the sql stuff for now. %macro lookback(date);
%local i lk_date month;
%let start=%sysfunc(inputn(&date,yymmn6.));
%do i=0 %to 11;
%put date = &date.;
%let lk_date=%sysfunc(intnx(month,&start,-&i,e),yymmn6.);
%put Lookback_Date = &lk_date.;
%put month = &i.;
proc sql;
----------------
%end;
data val;
merge datasets;
run;
%mend; The problem that I am facing is when I run the first macro for dates (201806-201812), instead of going 201806, 201809, 201812 as the final datasets, the macro loops to 201806, 201809 and 201903. I am struggling to understand why the last dataset is moving 2 quarters instead of 1. Can anyone help? %extract_all
(
start = 201806,
end = 201812,
interval = quarter
);
... View more