Sample 24765: Create a SAS® date value from month and year text strings
When given a month name and year and you desire to create a SAS date, use the SUBSTR function to extract the first three bytes of the month name. Concatenate this result with a day value and Year variable, and pass it through the INPUT function along with the DATE9. informat.
The sample code on the Full Code tab illustrates this.
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.
data one;
input month :$10. year $4.;
chardate=CATT('01',substr(month,1,3),year);
/* For releases prior to SAS 9.0 where CATT is not available, */
/* use the commented line below instead of the assignment */
/* statement above to create CHARDATE. */
*chardate='01'||substr(month,1,3)||year;
sasdate=input(chardate,date9.);
format sasdate mmddyy10.;
datalines;
June 2004
January 2000
November 2001
March 2002
;
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 month year chardate sasdate
1 June 2004 01Jun2004 06/01/2004
2 January 2000 01Jan2000 01/01/2000
3 November 2001 01Nov2001 11/01/2001
4 March 2002 01Mar2002 03/01/2002
Type: | Sample |
Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions ==> Date and Time
|
Date Modified: | 2005-12-16 03:02:58 |
Date Created: | 2004-09-30 14:09:12 |
Operating System and Release Information
SAS System | Base SAS | Tru64 UNIX | 9 TS M0 | n/a |
OpenVMS Alpha | 9 TS M0 | n/a |
HP-UX IPF | 9 TS M0 | n/a |
Linux | 9 TS M0 | n/a |
64-bit Enabled Solaris | 9 TS M0 | n/a |
64-bit Enabled HP-UX | 9 TS M0 | n/a |
64-bit Enabled AIX | 9 TS M0 | n/a |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9 TS M0 | n/a |
z/OS | 9 TS M0 | n/a |