BookmarkSubscribeRSS Feed
mlogan
Lapis Lazuli | Level 10

Can anyone tell me the code how to create a new variable (Day_Diff) and calculate the day difference between Start_Date and End_Date of the following table?

My dates are Numeric and Date9. format.

ID    Start_Date  End_Date

1     12/01/2014  12/14/2014

1     01/01/2014  01/06/2014

1     01/01/2014  01/06/2014

1     10/01/2012  10/05/2012

2     01/01/2014  01/05/2014

2     12/01/2014  12/03/2014

2     12/01/2014  12/07/2014

2     02/11/2014  02/15/2014

2     01/01/2014  01/11/2014


I would much appreciate your help.

Thanks,

3 REPLIES 3
Steelers_In_DC
Barite | Level 11

day_diff = intck('day',start_date,end_date);

Astounding
PROC Star

Perhaps more simply, you could code:

days_diff = end_date - start_date;

SAS stores its dates on a numeric integer scale, where each passing day is one more than the day before.

MichelleHomes
Meteorite | Level 14

I suggest reading 's blog post about calculating an age, http://blogs.sas.com/content/sasdummy/2011/07/12/computing-age-in-sas-9-3/ Depending on your SAS version and your precision requirement, there are many ways.

>>> Oops! Just realised you were asking about days... a simple subtraction will work. I thought you were referring to years. :smileyblush:

Kind Regards,

Michelle

Message was edited by: Michelle Homes

//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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