I am trying to adapt some code that relies on a date field so that can run it for a number of month ends, I have done the inevitable google searches and got the code below to run a loop but whilst I have no problem having the start date as an input, ideally I would like to make the months input to be calculated as the number of months from the start date input to today's system date .
The next thing is that I need to understand how to include the date from the each run of the loop as the criteria for a number of different pieces of SAS code that will follow after. So currently the code I am running uses the date variable &EMTH_SQL1 that has come from a previous piece of code in a PROC SQL statement via a "WHERE" statement (e.g. WHERE BAL_DATE=&EMTH_SQL1) where &EMTH_SQL1 is the most recent end of month date. I need to understand how I change this statement to use the "e" variable to run the loop (which would be 87 times over using the example piece of code I have shown below, although as mentioned I would like to make this dynamic). The final bit is when I have created the data set using Proc SQL how I insert the month end date into the final data set name so that I have (in this case) 87 data sets with different names reflecting the different month end dates
The next thing is that I am posting this at 9am UK time July 28th and need turnaround in hours
%macro get_data(start=, months=87);
/* Convert start/end values into SAS dates */
%let start_dt = %sysfunc(inputn(&start., date9.));
%do i = 0 %to &months.;
/* Calculate the start and end months for the month of data in the loop */
%let month_e = %sysfunc(intnx(month, &start_dt., &i., E) );
%put %cmpres( %sysfunc(putn(&month_e., date9.)));
/***********************************/
/***** SQL/DATA Step goes here *****/
/***********************************/
%end;
%mend;
%get_data(start=31JAN2011);