Desktop productivity for business analysts and programmers

Distance between days

Reply
New Contributor
Posts: 3

Distance between days

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?

Super User
Posts: 22,820

Re: Distance between days

Posted in reply to dlansdowne0090

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. 

 

 

Occasional Contributor
Posts: 6

Re: Distance between days

Posted in reply to dlansdowne0090

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

PROC Star
Posts: 1,258

Re: Distance between days

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

Super User
Posts: 5,824

Re: Distance between days

Posted in reply to dlansdowne0090
@TomKari it definitely looks more advanced 😆
Data never sleeps
Super User
Posts: 9,550

Re: Distance between days

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'.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
PROC Star
Posts: 1,258

Re: Distance between days

Posted in reply to KurtBremser

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

 

Tom

Community Manager
Posts: 3,347

Re: Distance between days

Posted in reply to dlansdowne0090

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

PROC Star
Posts: 1,258

Re: Distance between days

Posted in reply to ChrisHemedinger

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

Ask a Question
Discussion stats
  • 8 replies
  • 625 views
  • 3 likes
  • 7 in conversation