I would like to filter my dataset to the last three months starting from the first of the month in SAS.
I have the following for the yesterday and the last 15 days with macro:
DATA _NULL_;
yesterday=put(INTNX('day',&today,-1),DATE11.);
twoweeksago=put(INTNX('day',&today,-15),DATE11.);
/*threemonths = put(intnx('month', &today, -3, 'same')*/
call symput('rpt_dt',yesterday);
call symput('rpt_dt2',twoweeksago);
/*call symput('rpt_3',threemonths);*/
RUN;
I tried modifying the yesterday and twoweeks ago lines, as you can see from the commented out lines, but this only works three months from today, which means I am filtering all the way to June 23rd and not the June 1st.
For now the work around is to be explicit about how many days since June 1st, but I am thinking there could be a way to code what I am trying to do.
threemonths = put(intnx('month', &today, -3, 'same')
That's close! Do you happen to know what the 'same' parameter does? It's an alignment specifier. See the intnx documentation for the other options - beginning
, middle
, end
(or their initial letter).
threemonths = put(intnx('month', &today, -3, 'B')
That will start on the 1st of the month 3 months ago.