I extracted some code(from SAS communities) to calculate the nth business day of the month. It is a little off. I was testing the code to make sure it returned the 3rd day of the month. I noticed Jul ,Aug, and Oct were giving me the 4th day instead. All these months have 31 days so wondering if that is the reason.
I want the 3 day of the month and will adjust for holidays for Jan, Jul and Sept only when it falls on a weekend. Can anyone confirm what is happening in these months and maybe how to accommodate the 1 day difference.
Does SAS have a US holilday calendar?
data test;
format business_day1 business_day2 business_day3 business_day4 business_day5 date9.;
business_day1 = intnx('weekday', intnx('month', '23jun2024'd, 0, 'b'), 3);
business_day2 = intnx('weekday', intnx('month', '18jul2024'd, 0, 'b'), 3);
business_day3 = intnx('weekday', intnx('month', '06aug2024'd, 0, 'b'), 3);
business_day4 = intnx('weekday', intnx('month', '11sep2024'd, 0, 'b'), 3);
business_day5 = intnx('weekday', intnx('month', '25oct2024'd, 0, 'b'), 3);
run;
INTNX WEEKDAY increments by business days, so you need to start on the last day of the previous month for your calculations to always work correctly. For example 1 Jul 2024 is a Monday and the first business day in the month. If you increment by three business days that is 4 Jul. Try this:
data test;
format business_day1 business_day2 business_day3 business_day4 business_day5 date9.;
business_day1 = intnx('weekday', intnx('month', '23jun2024'd, -1, 'E'), 3);
business_day2 = intnx('weekday', intnx('month', '18jul2024'd, -1, 'E'), 3);
business_day3 = intnx('weekday', intnx('month', '06aug2024'd, -1, 'E'), 3);
business_day4 = intnx('weekday', intnx('month', '11sep2024'd, -1, 'E'), 3);
business_day5 = intnx('weekday', intnx('month', '25oct2024'd, -1, 'E'), 3);
put _All_;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: