|
On Thu, 18 Oct 2007 09:05:41 -0700, BJMurphy <murphy.ben@GMAIL.COM> wrote:
>Hi All,
>
>I want to figure out whether today is the first business day of the
>month in my code so that if I run the job every day, it automatically
>handles certain tasks on the first business day of the month. Assume
>that weekends and US federal/bank holidays are the only non-business
>days. I have this code that works within a data step and takes a SAS
>date variable (date) and determines if it is a holiday or not:
>
> mmdd = substr(put(date,mmddyy6.),1,4);
> if (weekday(date) in (1,7)) then date_type = 'w'; /* weekend */
> else if
> (mmdd in ('0101','0704','1111','1225')) or
> (weekday(date) = 2 and
> ((mmdd in ('0102','0705','1112','1226') or
> '0115' <= mmdd <= '0121' or
> '0215' <= mmdd <= '0221' or
> '0525' <= mmdd <= '0531' or
> '0901' <= mmdd <= '0907' or
> '1008' <= mmdd <= '1014'))) or
> (weekday(date) = 5 and '1122' <= mmdd <= '1128')
> then date_type = 'h'; /* holiday */
> else date_type = 'b'; /* business day */
>
>I can't decide the best way to figure out whether today was the first
>business day or not. It seems like I could either populate a data set
>with the last 31 days and test each one in succession, setting this
>date_type appropriately, but I feel like this sort of inelegant brute
>force method has some superior alternative.
>
>Any suggestions would be great.
>
>Thanks,
>Ben
Loop through the days from say 1 Jan. 1900 to 31 December 2099 (or some
other interval which is assuredly a superset of your actual days of
interest) and populate a data set with yes/no flags indicating whether each
is or is not first business day. Create a format from this table.
|