Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
sqlcode1 wrote:
It took me sometime to understand the solution and it will be premature for me to say its a bug so I am going to ask question. In the first step you would have already accounted for Saturday (subtract 1 day) and Sunday (add 1 day) to get to actual holiday but in step 2 you are going by Next Monday and then matching the value with holiday, which "probably" won't work. For example, if year is 2009 and input date is 20090403 the computed date comes to 20090704 which is 4th of July holiday.
I am having too many typos and misunderstandings today so I am not even going to attempt a solution but this solution is a keep for future requirements.
Thanks,
Well you are close , as the bug is when the holiday falls on a Friday, the logic would fail. I was simply adding 1 day if it is a holiday. So that would result in a saturday date which is a weekend. Also the same is the case with Thanks giving day. We need to get the NEXT monday for these dates and then validate to check if that monday is a holiday and then another day to it.
The conditions are
Code:
IF COMPUTED_DATE_DAY_OF_WEEK = 'SATURDAY' OR
COMPUTED_DATE_DAY_OF_WEEK = 'SUNDAY' OR
COMPUTED_DATE = 'THANKS GIVING' OR
COMPUTED_DATE = 'DAY AFTER TG')
INCREMENT THE DATE TO NEXT MONDAY
END-IF
IF (COMPUTED_DATE = 'NEW YEARS' OR
COMPUTED_DATE = 'INDEPENDENCE DAY' OR
COMPUTED_DATE = 'CHRISTMAS' OR
COMPUTED_DATE = 'NEW YEARS PREV DAY') AND
COMPUTED_DATE_DAY_OF_WEEK = 'FRIDAY'
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
There was a little confusion with my earlier reply. I didn't notice sqlcode1's, which wasn't there when I started typing but was by the time I finished double-checking.
The problem is, after 1st October, any addition of three months takes you into the following year, yet the holidays set up (only Ney Year's Day and Martin Luther King's birthday are relevant for three months) are the wrong ones to check against.
With concordance I've attempted to resolve this.
The idea is to disturb Kolusu's code as little as possible (cos it is easier that way).
For the fanatics, I'm afraid this includes an extra step.
The idea is to generate the SYMNAMES Kolusu later uses. A "Starting Point" date is used for SORTIN, so that production of the dates does not rely on the sort being run on a particular day.
Instead of the full date for the model holidays, only the MMDD is used as constants in the step. The year from the Starting Point is pre-pended. If the MMDD of the holiday is less than the MMDD of the Starting Point, Starting-Point-Plus-One is the year used.
The output from this step is to go to the SYMNAMES DD of Kolusu's first step, with the DD * data for that step removed.
I've slightly amended the output from the second step to included the amended day number to make testing easier. I have "lightly" tested it.
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
By any chance if you have SAS you could try something like,
Code:
year=2012;
Holiday_name = 'NEW YEAR';
MDY_sas = mdy(1,1,Year); /* JANUARY 1ST */
Wk_Day = weekday(MDY_sas);
if Wk_Day = 7 then MDY_sas = MDY_sas - 1;/*-1 IF IT IS SATURDAY*/
else if wk_day = 1 then MDY_sas = MDY_sas + 1; /*+1 IF IT IS SUNDAY*/
output;
Holiday_name = 'MEMORIAL DAY';
MDY_sas = intnx('week.2',mdy(5,31,year),0); /* LAST MONDAY MAY */
output;
or the HOLIDAY function in SAS 9.2(HOLIDAY function does not take into account if the holiday falls on saturday or sunday)
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
We are now back to two steps. For the solution, anyway. There is a new first step, for testing only. It generates 364 days starting from, and including, the date supplied on SYSIN. NB the date chosen should be the same as that used as the Starting Point for the holiday calendar. The SORTOUT is later input into the second step of the solution (the third here, everyone keeping up?).
That step has further minor amendments. The ANY/NONE combination has been replaced with OUTREC and a single WHEN=INIT, and there is some "self-testing" included. If a weekend is identified as the output date, the date is saved to the right and obliterated with XXXXXXXX. This has been tested by changing the 1,7 to 1,6.
The OUTFIL lists, for testing purposes only, all dates which had to be changed to get a working day. Remove the OUTFIL for generating required dates.