In reply to Derek Morgan.

Thank you, Derek, for your share. Very useful paper. Great emphasis in your code example: "MUST associate begin and end with a date, time or datetime format as appropriate, otherwise user-defined interval will not work".

Here is the problem that I was and still mystified with. Custom intervals work fine when advancing (incrementing) date. However, when going back (decrementing) date, they produce incorrect results for BEFORE_DATE falling on a weekend or holiday; the results are off by one day earlier than they need to be.

I ran the following code to compare the same events, calendar, and shifts with the example provided in the blog post:

/* USING CUSTOM INTERVALS */
data WORK.WORKDAYS (rename=(DATE=BEGIN));
set DAYS_WEEKENDS_AND_HOLIDAYS(where=(WORK_DAY=1));
format DATE date9.;
run;

options INTERVALDS=(workdays=WORK.WORKDAYS);

data EVENTS_WITH_SHIFTS1;
set EVENTS;
BEFORE_DATE = intnx('workdays',EVENT_DATE,-10); /* Decrement EVENT_DATE by 10 workdays - INCORRECT RESULTS*/
AFTER_DATE = intnx('workdays',EVENT_DATE, 12); /* Increment EVENT_DATE by 12 workdays */
format BEFORE_DATE AFTER_DATE date9.;
run;

proc compare base=EVENTS_WITH_SHIFTS compare=EVENTS_WITH_SHIFTS1;
run;

In order to produce correct results matching the example in this blog post, I had to modify the INTNX() function arguments to be
BEFORE_DATE = intnx('workdays',EVENT_DATE-1,-(10-1)), see below:

data EVENTS_WITH_SHIFTS1;
set EVENTS;
BEFORE_DATE = intnx('workdays',EVENT_DATE-1,-(10-1)); /* Decrement EVENT_DATE by 10 workdays - CORRECT RESULTS*/
AFTER_DATE = intnx('workdays',EVENT_DATE, 12); /* Increment EVENT_DATE by 12 workdays */
format BEFORE_DATE AFTER_DATE date9.;
run;

proc compare base=EVENTS_WITH_SHIFTS compare=EVENTS_WITH_SHIFTS1;
run;

I couldn't explain such a behavior and that is why I resorted to a more intuitive (at least to me) way of solving this problem with user-defined format.