## SAS Dates

Solved
Super Contributor
Posts: 1,041

# SAS Dates

I have two dates.. and i am trying to find the number of days

i was trying two methods and get contrasting results for each

Which of these is the right method????????

date1     (discharge date)                   date2( surgery date)

03MAY2012:13:39:00.000                   02MAY12:15:30:00

/*METHOD1*/

days=date1-date2

days_1=datepart(days);                                 /* gives me days_1= 0 */   post surgery days

/*METHOD2*/

days=datepart(date1)-datepart(date2)       /* gives me days= 1 */      post surgery days

Thanks

Accepted Solutions
Solution
‎07-19-2013 06:45 PM
Super User
Posts: 13,498

## Re: SAS Dates

For most processes that is 1 calendar day, which usually isn't an overestimation and you mentioned finding days. If you need 24 hour periods instead of calendar days you'll probably need to use the INTCK function to count specified intervals of time.

All Replies
Super User
Posts: 13,498

## Re: SAS Dates

Method 2 is what I would be using generally.

A third approach if were to make sense for your use would be to get the time interval, such as total hours and turn that into 24-hour periods.

Super Contributor
Posts: 1,041

## Re: SAS Dates

Why Method2: ??????it isnt it over estimating the days?????

Solution
‎07-19-2013 06:45 PM
Super User
Posts: 13,498

## Re: SAS Dates

For most processes that is 1 calendar day, which usually isn't an overestimation and you mentioned finding days. If you need 24 hour periods instead of calendar days you'll probably need to use the INTCK function to count specified intervals of time.

Super Contributor
Posts: 1,041

## Re: SAS Dates

Hi,

I also wanted to correct the usage..Is the extra braces needed as in the second case?or firstone is perfectly fine?

days=datepart(date1)-datepart(date2);

days=(datepart(date1)-datepart(date2));

Thanks

Super User
Posts: 13,498