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

Hi.  I'm wondering what would be the best way to determine the number of days between two SAS date variables and return it as a number variable?

 

Any suggests would be very helpful.  

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Use the INTCK Function like this

 

data _null_;
   date1='01jan2019'd;
   date2=today();
   days=intck('day', date1, date2);
   put days=;
run;

View solution in original post

6 REPLIES 6
Reeza
Super User
Depends a bit on your data structure, but you can just subtract dates to get durations.
buechler66
Barite | Level 11

What do you mean depending on data structure?  As an example I'd be looking at dates stored like:

03-FEB-2019 minus 01-FEB-2019 to return 2 as the number of days.

 

Does that make sense?  

Reeza
Super User

It depends on if your dates are SAS dates with a numeric format and not character. 

It also depends on whether both dates are in the same line or not - if you need to look behind or forward you would use different techniques. At the end of the day, a difference calculation is all you need. 

 


@buechler66 wrote:

What do you mean depending on data structure?  As an example I'd be looking at dates stored like:

03-FEB-2019 minus 01-FEB-2019 to return 2 as the number of days.

 

Does that make sense?  


 

 

PeterClemmensen
Tourmaline | Level 20

Use the INTCK Function like this

 

data _null_;
   date1='01jan2019'd;
   date2=today();
   days=intck('day', date1, date2);
   put days=;
run;
buechler66
Barite | Level 11
Thanks so much for the example. I appreciate you taking the time.
ChanceTGardener
SAS Employee

For number of days between two SAS dates, you can just subtract one from the other. Behind the scenes, a SAS date is just a number (# of days since Jan. 1, 1960). 

 

data x;
 date1='01JAN2019'd;
 date2='04FEB2019'd;
 days_between=date2 - date1;
* format date1 date2 mmddyy10.;
run;

proc print data=x; run;

If you want the number of weeks, months, quarters, etc. between two SAS dates, check out the intck() function. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 40378 views
  • 4 likes
  • 4 in conversation