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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.