Reputation: 13
I'm working on a code that gets tables dynamically and associates them with calculated dates for further calculations. I have trouble calculating these dates because their values won't change if i change the only parameter I start with.
PS : I opted to do them inside data null step so I can use them for other queries.
%let dtDMRT= 1FEB2016;
/*calculated dates */
DATA _null_;
DAY_DMRT_DEB = intnx('year',"&dtDMRT"d,-1);
format DAY_DMRT_DEB DATE9.;
call symputx('DAY_DMRT_DEB',DAY_DMRT_DEB);
DAY_DMRT_FIN = '&dtDMRT'd;
format DAY_DMRT_FIN DATE9.;
call symputx('DAY_DMRT_FIN',DAY_DMRT_FIN);
DATE_DMRT_1Y = intnx('year',"&dtDMRT"d,1);
format DATE_DMRT_1Y DATE9.;
call symputx('DATE_DMRT_1Y',DATE_DMRT_1Y);
run;
PROC SQL THREADS ;
CREATE TABLE DATAMART_SEG AS
SELECT *,
&DAY_DMRT_DEB as DAY_DMRT_DEB format= DATE9.,
&DAY_DMRT_FIN as DAY_DMRT_FIN format= DATE9.,
&DATE_DMRT_1Y As DATE_DMRT_1Y format= DATE9.
FROM DMRT.MYDATAMART_&dtDMRT
RUN;
The first test with %let dtDMRT= 1JAN2016; I get the right results in WORK.DATAMART_SEG :
DAY_DMRT_DEB = '01JAN2015'd
DAY_DMRT_FIN = '01JAN2016'd
DATE_DMRT_1Y = '01JAN2017'd
How ever with %let dtDMRT= 1FEB2016; I get :
DAY_DMRT_DEB = '01JAN2015'd
DAY_DMRT_FIN = '01FEB2016'd
DATE_DMRT_1Y = '01JAN2017'd
I know I can do this directly into the table with either PROC SQL or DATA step but I need those macro variables for other purposes
Upvotes: 0
Views: 51
Reputation: 1427
According to the documentation for intnx the default for alignment is set to BEGINNING. So what you observing is absolutely correct. Set the alingment to SAME and intnx will do what you want.
DATA _null_;
DAY_DMRT_DEB = intnx('year',"&dtDMRT"d,-1,'SAME');
format DAY_DMRT_DEB DATE9.;
call symputx('DAY_DMRT_DEB',DAY_DMRT_DEB);
DAY_DMRT_FIN = "&dtDMRT"d;
format DAY_DMRT_FIN DATE9.;
call symputx('DAY_DMRT_FIN',DAY_DMRT_FIN);
DATE_DMRT_1Y = intnx('year',"&dtDMRT"d,1,'SAME');
format DATE_DMRT_1Y DATE9.;
call symputx('DATE_DMRT_1Y',DATE_DMRT_1Y);
run;
Upvotes: 1