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.
Use the INTCK Function like this
data _null_;
date1='01jan2019'd;
date2=today();
days=intck('day', date1, date2);
put days=;
run;
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?
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?
Use the INTCK Function like this
data _null_;
date1='01jan2019'd;
date2=today();
days=intck('day', date1, date2);
put days=;
run;
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.