BookmarkSubscribeRSS Feed
bibbnd
Fluorite | Level 6

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;

1 REPLY 1
SASKiwi
PROC Star

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;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 239 views
  • 2 likes
  • 2 in conversation