I have the following data and I need to calculate the difference between FINISHED and STARTED minus any weekends (any Saturdays and any Sundays) and also minus any holidays that might exist between the two dates.
Obs | Started | Finished |
1 | Wednesday, August 28, 2013 | Thursday, November 14, 2013 |
2 | Tuesday, June 18, 2013 | Monday, November 25, 2013 |
3 | Tuesday, July 23, 2013 | Friday, November 8, 2013 |
4 | Wednesday, September 11, 2013 | Friday, November 15, 2013 |
5 | Wednesday, September 18, 2013 | Thursday, December 5, 2013 |
6 | Wednesday, July 24, 2013 | Tuesday, December 3, 2013 |
7 | Friday, October 4, 2013 | Monday, November 11, 2013 |
8 | Tuesday, August 27, 2013 | Wednesday, November 27, 2013 |
9 | Wednesday, October 2, 2013 | Wednesday, November 6, 2013 |
10 | Thursday, July 11, 2013 | Monday, November 4, 2013 |
I know how to calculate the number of days difference between the two variables, but I don't know how to do this other additional step.
For my purposes, the holidays which exist in the above time periods are only the following holidays:
Thursday, July 04, 2013 | Independence Day |
Monday, September 02, 2013 | Labor Day |
Monday, October 14, 2013 | Columbus Day |
Monday, November 11, 2013 | Veterans' Day |
Thursday, November 28, 2013 | Thanksgiving |
Wednesday, December 25, 2013 | Christmas Day |
Tuesday, December 31, 2013 | New Year's Eve |
I think the general solution is to build a dataset consisting of the days you consider to be "work" days and then summing those. There's a support doc on how to do it.
26044 - Determine the number of business days between two SAS dates
proc sql;
create table final_sql as
select startdt format=date9.,
stopdt format=date9.,
(select count(*)
from calendar
where dt between stopdt and startdt
and type = 'Workday') as workdays
from test;
quit;
check this out:
data holiday;
input holiday date9.;
cards;
24Dec2013
25Dec2013
31Dec2013
01Jan2014
;
data real_date;
input real_date date9.;format real_date date9.;
cards;
20Dec2013
21Dec2013
22Dec2013
23Jan2013
24Dec2013
25Dec2013
26DEC2013
27DEC2013
28DEC2013
29DEC2013
30Dec2013
31DEC2013
01JAN2014
02JAN2014
05JAN2014
10JAN2014
12JAN2014
14JAN2014
15JAN2014
;
proc sql noprint;
select holiday into :holiday separated by ',' from holiday;
quit;
data test;
set real_date(where=(weekday(real_date) not in (1,7) and real_date not in (&holiday.)));
Diff=intck('day','14JAN2014'd,real_date);
run;
Take a look at Chris Hemdinger's blog post at:
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: