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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1529 views
  • 0 likes
  • 3 in conversation