BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
avepo
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Use the INTNX function:

 

date_before = intnx("MONTH", date, -3, "SAME");
date_after = intnx("MONTH", date, 3, "SAME");


PG

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
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;

 

PGStats
Opal | Level 21

Use the INTNX function:

 

date_before = intnx("MONTH", date, -3, "SAME");
date_after = intnx("MONTH", date, 3, "SAME");


PG
avepo
Fluorite | Level 6

Thanks! It worked.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2029 views
  • 0 likes
  • 3 in conversation