A #SASJuletip advent calendar about a calendar 😉 You might already be using the INTCK functions to calculate various distances between different standard dates, but there are some limitation as it does not handle national bank holidays or perhaps even special company holidays. As always there are many ways to accomplice this, but this #SASjuletip will introduce an old and perhaps a little know/used feature. Imagine these dates. How many days are between the dates marked with yellow? Properly different answers depending on your country. And it can be calculated using SAS in many different ways, depending on what you want and your preferred method. Below is one way, using a simple example of introducing Custom Date Intervals used together with INTCK(). * Table with public bank holidays we will not count a workdays *;
* http://www.nationalbanken.dk/da/Kontakt/aabningstider/Sider/Default.aspx *;
data bankdays;
attrib begin format=date. ;
infile datalines dlm=':';
input begin :anydtdte18. beskrivelser $30.;
datalines;
1. januar 2019 : Nytårsdag
18. april 2019 : Skærtorsdag
19. april 2019 : Langfredag
22. april 2019 : 2. påskedag
17. may 2019 : Store bededag
30. may 2019 : Kristi himmelfartsdag
31. may 2019 : Banklukkedag
5. june 2019 : Banklukkedag
10. june 2019 : 2. pinsedag
24. december 2019 : Banklukkedag
25. december 2019 : Juledag
26. december 2019 : 2. juledag
31. december 2019 : Banklukkedag
1. januar 2020 : Nytårsdag
;
run;
proc sort data=bankdays;
by begin;
run;
* All dates, but not saturday/sundays *;
data xdanish(keep=begin);
format begin date9.;
do begin = '20dec2019'd to '05jan2020'd;
if weekday(begin) not in (1,7) then output; * not sat/sun *;
end;
run;
proc sort data=xdanish;
by begin;
run;
* remove bank holidays from date tabel *;
data xdanish;
merge xdanish(keep=begin)
bankdays(keep=begin in=remove);
by begin;
if remove then delete;
run;
options intervalds=(xDanish=work.xdanish);
* TEST count days *;
data test;
format start end date.;
start = '20dec2019'd;
end = '22dec2019'd;
put (start end) (=);
day =intck('day', start, end); put day=;
wday=intck('weekday', start, end); put wday=;
xday=intck('xDanish', start, end); put xday= /;
output;
start = '23dec2019'd;
end = '27dec2019'd;
put (start end) (=);
day =intck('day', start, end); put day=;
wday=intck('weekday', start, end); put wday=;
xday=intck('xDanish', start, end); put xday= /;
output;
start = '20dec2019'd;
end = '2jan2020'd;
put (start end) (=);
day =intck('day', start, end); put day=;
wday=intck('weekday', start, end); put wday=;
xday=intck('xDanish', start, end); put xday=;
output;
run; Do you agree with the counts? Or did your expect another result? How would you solve this? More reading: About Date and Time Intervals INTCK function Date and Time Intervals INTERVALDS= System Option Paper: Sometimes One Needs an Option with Unusual Dates Intervals, Enhanced Dating for SAS® Programmers DATDIF Function Btw are you familiar with HOLIDAY Function (7 different) but limited regarding holidays NWKDOM Function
... View more