DATA Step, Macro, Functions and more

Calculate Days between tow dates

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 119
Accepted Solution

Calculate Days between tow dates

Two date as:

CLCL_PAID_DT=22NOV2017:00:00:00.000

CLCL_RECD_DT =12NOV2017:00:00:00.000

 

My code:

INTCK('DAY',t1.CLCL_PAID_DT,t1.CLCL_RECD_DT,'C') AS Age1,

DATDIF(t1.CLCL_PAID_DT,t1.CLCL_RECD_DT,'act/act') AS Age

 

but both without value. Why


Accepted Solutions
Solution
‎12-08-2017 01:30 PM
Super User
Posts: 13,283

Re: Calculate Days between tow dates

In SAS what you show is a DATETIME, not a DATE. This is a critical difference as dates use numbers of days as the interval and datetimes are numbers of seconds. Due to a number of issues the range of date values that work with the various functions are limited to dates before the year 20,000. Most datetimes, when treated as dates without conversion, vastly exceed that range.

 

Hence the options of the DTDay, DTMONTH and DTYear functions to address the increments of datetimes instead of dates so the proper conversion is used.

 

OR explicitly use the DATEPART of a datetime value.

View solution in original post


All Replies
Super User
Posts: 23,224

Re: Calculate Days between tow dates

I think the interval is DTDAY or DAYDT when dealing with date times?

Solution
‎12-08-2017 01:30 PM
Super User
Posts: 13,283

Re: Calculate Days between tow dates

In SAS what you show is a DATETIME, not a DATE. This is a critical difference as dates use numbers of days as the interval and datetimes are numbers of seconds. Due to a number of issues the range of date values that work with the various functions are limited to dates before the year 20,000. Most datetimes, when treated as dates without conversion, vastly exceed that range.

 

Hence the options of the DTDay, DTMONTH and DTYear functions to address the increments of datetimes instead of dates so the proper conversion is used.

 

OR explicitly use the DATEPART of a datetime value.

Frequent Contributor
Frequent Contributor
Posts: 119

Re: Calculate Days between tow dates

Thank you,

INTCK('DTDAY',CLCL_RECD_DT,CLCL_PAID_DT)

 

works.

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 152 views
  • 0 likes
  • 3 in conversation