Hi all,
I need to calculate SAS dates 3 month before and 3 month after given dates but not adding or subtracting 90 days
For example,
I would like to know the dates (3 month before and after) using the given dates
3 month before | Given date | 3 month after |
10/1/2017 | 1/1/2017 | 4/1/2017 |
11/1/2017 | 2/1/2017 | 5/1/2017 |
12/1/2017 | 3/1/2017 | 6/1/2017 |
Adding or subtracting 90 days do not give me the same dates with different months.
Does anyone know how to calculate these types of dates?
Thanks!
Use the INTNX function:
date_before = intnx("MONTH", date, -3, "SAME");
date_after = intnx("MONTH", date, 3, "SAME");
data want;
set have;
th3mthbfr=intnx('month', givrndate,-3,'s');
th3mthaftr=intnx('month', givrndate,3,'s');
format th3mthbfr th3mthaftr mmddyy10.;
run;
data want;
set have;
th3mthbfr=intnx('month', givrndate,-3);
thrmthaftr=intnx('month', givrndate,3);
run;
Use the INTNX function:
date_before = intnx("MONTH", date, -3, "SAME");
date_after = intnx("MONTH", date, 3, "SAME");
Thanks! It worked.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.