BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Q1983
Lapis Lazuli | Level 10

I have seen posts regarding use of the date diff function. 

 

1. I need to take a date say a variable called my_date, add 5 years to it  (ie the my_date is always hardcoded on the 1st, 9/1/2010)  5 years from that date is 9/1/2015

2  Now I need to take that resulting date of 9/1/2015 and add 14 days to display if as 9/15/2015 as I always want the 15th of the month

3  Finally I need to subtract 4 months and show a final my_date as 5/15/2015

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

1. INTNX with Year -> intnx('year', date, 5, 's')

2. INTNX with Day (or just add 14)-> intnx('day', date, 14)

3. INTNX with Month -> intnx('month', date, -4, 's')

 

So, use the INTNX function to calculate your dates.

 

data want;
date1=mdy(9, 1, 2010);
date2=intnx('year', date1, 5, 's');
date3=intnx('day', date2, 14);
date4=intnx('month', date3, -4, 's');
format date: date9.;
run;

proc print;run;

 

 

 

 

View solution in original post

3 REPLIES 3
ballardw
Super User

Look at the function INTNX. Your requirements would require 3 calls to the function.

Reeza
Super User

1. INTNX with Year -> intnx('year', date, 5, 's')

2. INTNX with Day (or just add 14)-> intnx('day', date, 14)

3. INTNX with Month -> intnx('month', date, -4, 's')

 

So, use the INTNX function to calculate your dates.

 

data want;
date1=mdy(9, 1, 2010);
date2=intnx('year', date1, 5, 's');
date3=intnx('day', date2, 14);
date4=intnx('month', date3, -4, 's');
format date: date9.;
run;

proc print;run;

 

 

 

 

Ksharp
Super User

data want;

date1=mdy(9, 1, 2010);

date2=intnx('year', date1, 5, 's');

date3=intnx('day', date2, 14);

date4=intnx('month', date3, -4, 's');

date5=intnx('month', date1, 5*12, 'm');

format date: date9.;

run;

 

proc print;run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 936 views
  • 2 likes
  • 4 in conversation