Sample 36133: Finding the first business day of the month
The sample code on the Full Code tab takes a SAS date variable and finds the first business day of that month. It uses the INTNX function to advance to the first day of the month. Then it uses the WEEKDAY function to determine the day of the week. If the first day is a Saturday or Sunday, then it advances the FIRST variable by 2 or 1, respectively. No holidays are considered.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/* create sample data */
data one;
input date mmddyy6.;
format date date9.;
cards;
011517
021516
030417
;
data two;
set one;
/* advance date to the first day of the month using the INTNX function */
first=intnx('month',date,0);
/* determine the day of the week using the WEEKDAY function */
day=weekday(first);
/* if day=Sunday then advance by 1 */
if day=1 then first+1;
/* if day=Saturday then advance by 2 */
else if day=7 then first+2;
format first date9.;
proc print;
title 'First Business Day of the Month';
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
First Business Day of the Month
Obs date first day
1 15JAN2017 02JAN2017 1
2 15FEB2016 01FEB2016 2
3 04MAR2017 01MAR2017 4
This sample takes a date and then finds the first business day of the month.
| Type: | Sample |
| Topic: | SAS Reference ==> Functions ==> Date and Time ==> INTNX SAS Reference ==> Functions ==> Date and Time ==> WEEKDAY
|
| Date Modified: | 2009-06-04 10:18:51 |
| Date Created: | 2009-06-04 09:22:29 |
Operating System and Release Information
| SAS System | Base SAS | z/OS | | |
| OpenVMS VAX | | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | | |
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | | |
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | | |
| Microsoft Windows XP 64-bit Edition | | |
| Microsoft® Windows® for x64 | | |
| OS/2 | | |
| Microsoft Windows 95/98 | | |
| Microsoft Windows 2000 Advanced Server | | |
| Microsoft Windows 2000 Datacenter Server | | |
| Microsoft Windows 2000 Server | | |
| Microsoft Windows 2000 Professional | | |
| Microsoft Windows NT Workstation | | |
| Microsoft Windows Server 2003 Datacenter Edition | | |
| Microsoft Windows Server 2003 Enterprise Edition | | |
| Microsoft Windows Server 2003 Standard Edition | | |
| Microsoft Windows Server 2008 | | |
| Microsoft Windows XP Professional | | |
| Windows Millennium Edition (Me) | | |
| Windows Vista | | |
| 64-bit Enabled AIX | | |
| 64-bit Enabled HP-UX | | |
| 64-bit Enabled Solaris | | |
| ABI+ for Intel Architecture | | |
| AIX | | |
| HP-UX | | |
| HP-UX IPF | | |
| IRIX | | |
| Linux | | |
| Linux for x64 | | |
| Linux on Itanium | | |
| OpenVMS Alpha | | |
| OpenVMS on HP Integrity | | |
| Solaris | | |
| Solaris for x64 | | |
| Tru64 UNIX | | |