09-05-2016 08:21 AM
I am trying to loop the macro variable %M. The code is following:
%LET last_month_end_dt = 31oct2015:23:59:59.000;
do i = 0 to &num_months - 1;
a = "&last_month_end_dt"d;
format a date9.;
b = intnx('MONTH',a,-i,'end');
ddate = put(b,date9.)||":23:59:59.000";
There must be some problem with formatting - any tips how to make this work? Thanks
09-05-2016 08:31 AM
09-05-2016 08:41 AM
I have a code (macro called M) that does something. It is fed by two variables, as you wrote: TH,ddate. I am trying to avoid mannual running by setting:
%let ddate = 31oct2015:23:59:59.000;
%let ddate = 30sep2015:23:59:59.000;
So I created another variable in macro M (ddate) - there originally was just one variable. By looping through i i am trying to avoid manual running the code.
The problem is that ddate has value ddate instead of the dates:
15 data _null_;
16 do i = 0 to &num_months - 1;
SYMBOLGEN: Macro variable NUM_MONTHS resolves to 5
17 a = "&last_month_end_dt"d;
SYMBOLGEN: Macro variable LAST_MONTH_END_DT resolves to 31oct2015:23:59:59.000
18 format a date9.;
19 b = intnx('MONTH',a,-i,'end');
20 ddate = put(b,date9.)||":23:59:59.000";
21 call symput('ddate',"&ddate"d);
SYMBOLGEN: Macro variable DDATE resolves to 30JUN2015:23:59:59.000
MLOGIC(M): Beginning execution.
MLOGIC(M): Parameter COUNTRY has value TH
MLOGIC(M): Parameter DDATE has value ddate
09-05-2016 08:45 AM
09-05-2016 08:55 AM
I cannot post here the code for macro M. I only need to change the value of ddate from ddate to the dates
30JUN2015:23:59:59.000 when it beginns execution it said:
Parameter DDATE has value ddate
There must be ddate has value 30JUN2015:23:59:59.000
09-05-2016 08:53 AM - edited 09-05-2016 08:54 AM
This is only a wild guess as, as Cynthia_sas put, you don't provide the code for the macro function %M.
Doesn't this macro expect a value instead of the name of a macrovariable as its second argument. If so, it should be called as
09-05-2016 09:56 AM
The problem with trying to use &DDATE as you suggest is that you can't use a macro variable in the same DATA step program where you are creating it. In the example below, my macro program %M is not doing much except a simple PROC PRINT. But if the goal is to run the macro 1 time and only 1 time using 30JUN2015:23:59:59.000 as the value for &ddate, then my program does that. I did not use the DO loop in the program, because I didn't understand why it was needed when all the macro variables in the %LET could have been used inside a single INTNX.
As shown in my log, if you try to use &DDATE inside the DATA step program, it will not be resolved. But if you try to use &DDATE after the step boundary, then it will be used. I deleted (with %SYMDEL) the &DDATE macro variable before the program runs, just so it's not in the GLOBAL symbol table from a previous run.
09-05-2016 10:27 AM
Thank you very much for your help. The reason for loop in that data step was to produce all different dates, i.e.:
So that I would not have to mannually change %let ddate = 30Jun2016:23:59:000; to %let ddate = 31Jul2016:23:59:000; etc
I really appreciate your help. I managed to make a cycle inside macro M so there it is no longer needed to create another data step for looping the dates.