09-19-2014 09:59 PM
In this code I am getting the number of days between lm_set_up_dt and _585(which is a date)
I believe the ‘day’ function does not consider holidays and weekends it just provides a straight day difference.
Is there a way to have ‘day’ account for this by assigning the closest business day.(ie if one of the dates falls on Sunday can ‘day’ increment to Monday
(ie if _585 falls on Sunday 9/21/14 the code would allow _585 to increment to Monday 9/22/14 for calculation purposes. In our company we do have a previous business day variable called &pbday. I may need to learn how ‘day’ is read by sas
09-19-2014 10:39 PM
Look into 'weekday' instead of 'day', but it depends on your question.
Otherwise you can test if _585 is a day on Sat/Sun and increment. If you want to account for holidays it's more complicated.
if day(_585)=7 then date=_585+2;/*Saturday*/
if day(_585)=1 then date=_585+1;/*Sunday*/
age_585_v2=intck('weekday', lm_set_up_dt, date);
09-19-2014 11:01 PM
intck() will return the difference between to dates based on the interval you're using. With "day" it is the number of days between 2 dates.
There are other intervals. "weekday" is eventually what you're after: SAS(R) 9.4 Functions and CALL Routines: Reference, Third Edition
Weekday will give you the number of - as it says - week days between 2 dates (with Saturday and Sunday treated as week-end).
I'm not sure that I fully understand what you're after so won't try to take this further. Run below code and let us know if this gives you what you're after.
Holidays are regional so there is no general interval out of the box available (except for US wide valid holiday days). You can create your own custom interval to take regional holidays into account. It's all documented under the link I've posted.
format day_of_week downame.;
format lm_set_up_dt _585 date9.;
do _585='18Sep2014'd, '19Sep2014'd, '20Sep2014'd, '21Sep2014'd, '22Sep2014'd, '23Sep2014'd;
09-20-2014 05:23 AM
In the documentation link by Patrick also the intervalds option with custom intervals is mentioned.
You can define and use any interval definition as you like including own defined holidays business working days or business service hours.