BookmarkSubscribeRSS Feed
viollete
Calcite | Level 5

Hello,

I have all my info about dates in SAS format and I want from each date subtract nine months.

Is it possible to do?

2 REPLIES 2
LinusH
Tourmaline | Level 20

intnx()

Data never sleeps
RichardinOz
Quartz | Level 8

Linus' reply is a bit terse.  The intnx function will provide an answer, provided you supply the right question.  Do you want 9 calendar months exactly (ie to the same day - if possible - 9 months previously), or do you just need the month and the first day will do; or maybe push all dates back by the same amount (0.75 year = 274 days)?

Taking these options in reverse order:


Prev_date = date - 274 ;

Prev_date = intnx("MONTH", date, -9) ;

Prev_date = intnx("MONTH", date, -9, "SAME") ;


INTNX is documented here

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

BTW, if your dates are datetime intervals you need to use "DTMONTH" instead of "MONTH" ; and for the 274 day calculations use

Prev_date = intnx("DTDAY", date, -274, "SAME") ;


Richard

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
  • 2 replies
  • 443 views
  • 0 likes
  • 3 in conversation