Usage Note 42057: Writing a datetime value as m/d/y h:m:s AM/PM
The MDYAMPMw.d format writes datetime values in the form
mm/dd/yy hh:mm AM|PM
Since the MDYAMPMw.d informat reads values including seconds, you may want to output a like value that includes seconds.
PROC FORMAT with the PICTURE statement gives the flexibility to create custom formats. See the code under the Full Code tab for creating a format that writes output in the form
mm/dd/yy hh:mm:ss AM|PM
Operating System and Release Information
SAS System | Base SAS | z/OS | 9 TS M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9 TS M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9 TS M0 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9 TS M0 | |
Microsoft Windows 2000 Advanced Server | 9 TS M0 | |
Microsoft Windows 2000 Datacenter Server | 9 TS M0 | |
Microsoft Windows 2000 Server | 9 TS M0 | |
Microsoft Windows 2000 Professional | 9 TS M0 | |
Microsoft Windows NT Workstation | 9 TS M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9 TS M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9 TS M0 | |
Microsoft Windows Server 2003 Standard Edition | 9 TS M0 | |
Microsoft Windows XP Professional | 9 TS M0 | |
64-bit Enabled AIX | 9 TS M0 | |
64-bit Enabled HP-UX | 9 TS M0 | |
64-bit Enabled Solaris | 9 TS M0 | |
HP-UX IPF | 9 TS M0 | |
Linux | 9 TS M0 | |
OpenVMS Alpha | 9 TS M0 | |
Tru64 UNIX | 9 TS M0 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
Since the MDYAMPMw.d format doesn't include seconds, PROC FORMAT creates a custom format with output like MDYAMPMw.d format, including seconds.
proc format;
picture myfmt low-high='%m/%d/%Y %I:%0M:%0S %p' (datatype=datetime);
run;
/* If you want single digit months and days to write leading zeros, change */
/* the format definition to this */
proc format;
picture myfmt low-high='%0m/%0d/%Y %I:%0M:%0S %p' (datatype=datetime);
run;
/* data read with MDYAMPM and then output with the custom format */
data mine;
input dt mdyampm22.;
format dt myfmt.;
datalines;
12/25/2010 1:30:02am
;
proc print;
run;
Obs dt
1 12/25/2010 1:30:02 AM
The MDYAMPM format writes datetime values without showing the seconds part of the time. PROC FORMAT allows you to write a custom format to show the seconds.
Type: | Usage Note |
Priority: | |
Topic: | SAS Reference ==> Formats ==> Date and Time SAS Reference ==> Procedures ==> FORMAT
|
Date Modified: | 2011-01-21 12:11:19 |
Date Created: | 2011-01-10 11:14:58 |