Sample 31443: How to find the number of days in the month regardless of your SAS® date value
The sample code on the Full Code tab uses two functions to obtain the number of days in the month of the SAS date provided. The two functions used in the example are INTNX and DAY.
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.
The INTNX function increments a date, time, or datetime value by a given time interval, and returns a date, time, or datetime value. The first argument to INTNX is the interval used for the calculation, the second argument is the starting date, the third argument specifies the number of intervals to move from the starting value, and while the fourth parameter is optional, we're specifying 'end' so that the last day of the interval is returned rather than the first day.
This code returns the last day of the month of the supplied date. Since the third parameter is 0, that indicates that we don't want to move forward or backward, but stay within the same month.
data one;
input date mmddyy6.;
eom=intnx('month',date,0,'end');
format eom date9.;
numdays=day(eom);
cards;
010108
020208
030308
040408
050508
060608
070708
080808
090908
101008
111108
121208
;
run;
proc print;
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.
Obs date eom numdays
1 17532 31JAN2008 31
2 17564 29FEB2008 29
3 17594 31MAR2008 31
4 17626 30APR2008 30
5 17657 31MAY2008 31
6 17689 30JUN2008 30
7 17720 31JUL2008 31
8 17752 31AUG2008 31
9 17784 30SEP2008 30
10 17815 31OCT2008 31
11 17847 30NOV2008 30
12 17878 31DEC2008 31
Type: | Sample |
Topic: | SAS Reference ==> Functions ==> Date and Time ==> DAY SAS Reference ==> Functions ==> Date and Time ==> INTNX
|
Date Modified: | 2011-06-20 15:11:40 |
Date Created: | 2008-03-12 15:16:09 |
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 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 | | |