BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8


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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

5 REPLIES 5
ballardw
Super User

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.

robertrao
Quartz | Level 8

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

ballardw
Super User

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.

robertrao
Quartz | Level 8

Hi,

Thanks for the reply,

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

ballardw
Super User

Both lines return the same result. The only time you would need the extra braces is in a more complex computation where you need to control the order of operations.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 842 views
  • 3 likes
  • 2 in conversation