BookmarkSubscribeRSS Feed
DartRodrigo
Lapis Lazuli | Level 10

Hi, i have a table with loads of dates.

I need a way to look this table everytime i run six months ago.

I use this Where my_date >= '14jul/2015:00:00:00'dt - 180;

But it does not work.

Tks,

Rodrigo Dartibali Elias

4 REPLIES 4
Reeza
Super User

datetime are in seconds, so 6 'months' ago is 30*24*60*60 seconds, except you have months that vary in length.

I recommend using intck or intnx functions.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

It does work, what you are doing is subtracting 180 miliseconds from 14Jul2015 and then any date which is >= to that output.  You need to understand how dates, times, and datetime variables are stored internally - read up in the manual on this.  As for your problem, I would recommend using intck:

where my_date >= intck('month',datepart('14jul2015:00:00:00'dt),-6)

What this is doing is first, taking the datepart of the datetime variable as we are not interested in time part.  Then it is using intck to move, as a monthly interval 6 months back, and finally using this date value as a comparison.

DartRodrigo
Lapis Lazuli | Level 10

Wow, this helps a lot, guys.

Thank you

ballardw
Super User

And go back and tell however named a DATETIME variable as a DATE to cut it out. :smileymischief:

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
  • 4 replies
  • 465 views
  • 2 likes
  • 4 in conversation