DATA Step, Macro, Functions and more

Function to check for a business day

Reply
Contributor
Posts: 21

Function to check for a business day

Is there a function in SAS that I can use to check if a given date is a business day and if its not a business day, then find the previous or the next business day?
SAS Super FREQ
Posts: 8,869

Re: Function to check for a business day

Posted in reply to model_coder
Hi:
In the simplest form, the WEEKDAY function can take a SAS date value as an argument and return the day of the week, as a number (1=Sunday, 2=Monday, etc, 7=Saturday). Using that returned value as a starting point, you can write logic to advance the date until the weekday function returns a value between 2-6 (Monday-Friday).

If by "business day" you mean something more sophisticated (such as taking holidays into account) and finding the next date, then you might need to use logic such as found in this Tech Support note:
http://support.sas.com/kb/26/044.html

cynthia
Contributor
Posts: 21

Re: Function to check for a business day

Posted in reply to Cynthia_sas
Thanks Cynthia. I already implemented a code that somewhat matches your suggestion. But then I ran into the issue of holidays. I guess we need to implement something more sophisticated as suggested in your tech note.
Thanks for help!
SAS Employee JLD
SAS Employee
Posts: 2

Re: Function to check for a business day

Posted in reply to model_coder

To find the next business day , use INTNX('WEEKDAY',...)  - see code below.

  if Thisdate = intnx('WEEKDAY',Thisdate,0) then NextWorkday=Thisdate; else NextWorkday=intnx('weekday',Thisdate,1);

To find the previous business day, simply use

    PreviousBusinessday = intnx('weekday',Thisdate,0) ;

This does not take into account holidays, only Saturday & Sunday.

In Saudi Arabia, where weekend is on Thursday & Friday, use this code instead

intnx('weekday56w',Thisdate,0) ;  see SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

Regular Contributor
Posts: 227

Re: Function to check for a business day

Posted in reply to model_coder

Yes, SAS does have a holiday function

http://www.sascommunity.org/wiki/Generating_Holiday_Lists

Ron Fehd sas.comm.wiki maven

PROC Star
Posts: 7,492

Re: Function to check for a business day

Posted in reply to model_coder

And, if you need to expand the holiday function to incorporate holidays that aren't already included in the holiday function, take a look at the customizable holiday function at: http://www.sascommunity.org/wiki/Sometimes_One_Needs_an_Option_with_Unusual_Dates

Ask a Question
Discussion stats
  • 5 replies
  • 8722 views
  • 1 like
  • 5 in conversation