BookmarkSubscribeRSS Feed
Bautista
Calcite | Level 5

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.

ObsStartedFinished
1Wednesday, August 28, 2013Thursday, November 14, 2013
2Tuesday, June 18, 2013Monday, November 25, 2013
3Tuesday, July 23, 2013Friday, November 8, 2013
4Wednesday, September 11, 2013Friday, November 15, 2013
5Wednesday, September 18, 2013Thursday, December 5, 2013
6Wednesday, July 24, 2013Tuesday, December 3, 2013
7Friday, October 4, 2013Monday, November 11, 2013
8Tuesday, August 27, 2013Wednesday, November 27, 2013
9Wednesday, October 2, 2013Wednesday, November 6, 2013
10Thursday, July 11, 2013Monday, 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, 2013Independence Day
Monday, September 02, 2013Labor Day
Monday, October 14, 2013Columbus Day
Monday, November 11, 2013Veterans' Day
Thursday, November 28, 2013Thanksgiving
Wednesday, December 25, 2013Christmas Day
Tuesday, December 31, 2013New Year's Eve
3 REPLIES 3
DBailey
Lapis Lazuli | Level 10

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;

pradeepalankar
Obsidian | Level 7

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 4381 views
  • 1 like
  • 4 in conversation