BookmarkSubscribeRSS Feed
dlansdowne0090
Calcite | Level 5

How can I calculate the days between a given date and dates imported to SAS EG via a csv file - dates in the Date9 format. Is it possible to do this via the query builder?

8 REPLIES 8
Reeza
Super User

Yes, do a compute field and subtract the dates. 

 

You can specify your date as '01Jan2016'd

It HAS to be specified in this manner. 

 

This assumes that when you imported the data you created a SAS date variable, it has a numeric type and a date format. 

 

 

Chokin
Fluorite | Level 6

As above you need to do a compute field

 

You can use the INTCK Function get the difference between days - i.e

 

INTCK('Day','01APR2016"D,"06APR2016"D)

 

The result in this example is 5

TomKari
Onyx | Level 15

And you can definitely use intck in the query builder. I don't know why, I just feel more "professional" using it to calculate number of days between two dates. Makes no sense, I know!

 

Tom

LinusH
Tourmaline | Level 20
@TomKari it definitely looks more advanced 😆
Data never sleeps
Kurt_Bremser
Super User

Usage of INTCK will be robust if SAS (ever) changes the internal format of date values.

It is also easier to adjust if datetime values need to be compared, as only 'DAY' needs to be changed to 'DTDAY'.

TomKari
Onyx | Level 15

Thank you Kurt! I now have a reasonable explanation for my OCD-like behaviour!!

 

Tom

ChrisHemedinger
Community Manager

In addition to the INTCK function -- super robust and flexible, as @TomKari and others point out, there is a simpler (conceptually) DATDIF function.  You can add as a Computed Column, Advanced Expression in the Query Builder.  Example:

 

DATDIF(t1.Shipped,t1.Returned,'act/act')

 

datdif.png

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
TomKari
Onyx | Level 15

Well, as I always tell people, there's at least twelve ways to do everything in SAS!

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 8 replies
  • 2104 views
  • 3 likes
  • 7 in conversation