Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Calculate difference of 2 dates except not countin...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-31-2014 03:43 PM

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 |

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-31-2014 04:22 PM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-31-2014 04:27 PM

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**;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-31-2014 05:36 PM

Take a look at Chris Hemdinger's blog post at: