| Formats |
| ISO 8601 Formatting Symbols |
The following list explains the formatting symbols that are used to notate the ISO 8601 dates, time, datetime, durations, and interval values:
| n |
specifies a number that represents the number of years, months, or days | ||||
| P |
indicates that the duration that follows is specified by the number of years, months, days, hours, minutes, and seconds | ||||
| T |
indicates that a time value follows. Any value with a time must begin with T.
| ||||
| W |
indicates that the duration is specified in weeks. | ||||
| Z |
indicates that the time value is the time in Greenwich, England, or UTC time. | ||||
| +|- |
the + indicates the time zone offset to the east of Greenwich, England. The - indicates the time zone offset to the west of Greenwich, England. | ||||
| yyyy |
specifies a four-digit year | ||||
| mm |
as part of a date, specifies a two-digit month, 01 - 12 | ||||
| dd |
specifies a two-digit day, 01 - 31 | ||||
| hh |
specifies a two-digit hour, 00 - 24 | ||||
| mm |
as part of a time, specifies a two-digit minute, 00 - 59 | ||||
| ss |
specifies a two-digit second, 00 - 59 | ||||
| fff | ffffff |
specifies an optional fraction of a second using the digits 0 - 9:
| ||||
| Y |
indicates that a year value proceeds this character in a duration | ||||
| M |
as part of a date, indicates that a month value proceeds this character in a duration | ||||
| D |
indicates that a day value proceeds this character in a duration | ||||
| H |
indicates that an hour value proceeds this character in a duration | ||||
| M |
as part of a time, indicates that a minute value proceeds this character in a duration | ||||
| S |
indicates that a seconds value proceeds this character in a duration |
| Writing ISO 8601 Date, Time, and Datetime Values |
SAS uses the formats in the following table to write date, time, and datetime values in the ISO 8601 basic and extended notations from SAS date, time, and datetime values.
| Date, Time, or Datetime | ISO 8601 Notation | Example | Format |
|---|---|---|---|
| Basic Notations | |||
| Date |
yyyymmdd |
20080915 | B8601DAw. |
| Time |
hhmmssffffff |
155300322348 | B8601TMw.d |
| Time with time zone | hhmmss+|-hhmm | 155300+0500 | B8601TZw.d |
|
|
hhmmssZ | 155300Z | B8601TZw.d |
| Convert to local time with time zone | hhmmss+|-hhmm | 155300+0500 | B8601LZw.d |
| Datetime | yyyymmddThhmmssffffff | 20080915T155300 | B8601DTw.d |
| Datetime with timezone | yyyymmddThhmmss+|-hhmm | 20080915T155300+0500 | B8601DZw.d |
|
|
yyyymmddThhmmssZ | 20080915T155300Z |
B8601DZw.d
|
| Write the date from a datetime |
yyyymmdd |
20080915 | B8601DNw. |
| Extended Notations | |||
| Date |
yyyy-mm-dd |
2008-09-15 | E8601DAw. |
| Time |
hh:mm:ss.ffffff |
15:53:00.322348 | E8601TMw.d |
| Time with time zone | hh:mm:ss.ffffff+|-hh:mm | 15:53:00+05:00 | E8601TZw.d |
| Convert to local time with time zone | hh:mm:ss.ffffff+|-hh:mm | 15:53:00+05:00 | E8601LZw.d |
| Datetime | yyyy-mm-ddThh:mm:ss.ffffff | 2008-09-15T15:53:00 | E8601DTw.d |
| Datetime with time zone | yyyy-mm-ddThh:mm:ss.nnnnnn+|-hh:mm | 2008-09-15T15:53:00+05:00 | E8601DZw.d |
| Write the date from a datetime |
yyyy-mm-dd |
2008-09-15 | E8601DNw. |
An asterisk ( * ) used in place of a date or time formatted value that is out-of-range.
| Writing ISO 8601 Duration, Datetime, and Interval Values |
SAS writes duration, datetime, and interval values from character data using these formats:
An omitted component can be represented by a hyphen ( - ) or an x in the extended datetime form yyyy-mm-ddThh:mm:ss and in the extended duration form Pyyyy-mm-ddThh:mm:ss.
Omitted components in the durations form PnYnMnDTnHnMnS are dropped, they do not contain a hyphen or x. For example, P2mT4H.
The following formats write omitted components that use the hyphen and the x:
Datetime values with omitted components that are formatted with either the $N8601B format or the $N8601BA format are formatted in the extended notation using the hyphen for omitted components to ensure accurate data. For example, when the month is an omitted component, the value 2008---15 is written and not 2008-15.
The extended notation with hyphens is also used in place of the basic notation if a duration is formatted by using the $N8601BA format. Using the same date, P2008---15 is written and not P2008-15.
Duration, datetime, or interval values can be truncated when one or more lower order values is 0 or is not significant. When SAS writes a truncated value using the formats $N8601B, $N8601BA, $N8601E, and $N8601EA, the display of the value stops at the last non-missing component.
When you format a truncated value by using either the $N8601H format or the $N8601EH format, the lower order components are written with a hyphen. When you format a truncated value by using the $N8601X format or the $N8601EX format, the lower order components are written with an x.
The following examples show truncated values:
When a value for a duration component is greater than the largest standard value for a component, SAS normalizes the component except when the duration component is a single component. The following table shows examples of normalized duration components:
| Duration | Extended Normalized Duration |
|---|---|
p3y13m |
p0004-01 |
pt24h24m65s |
P----01T-:25:05 |
p3y13mT24h61m |
P0004-01-01T01:01 |
p0004-13 |
p0005-01 |
p0003-02-61T15:61:61 |
P0003-04-01T16:02:01 |
p13m |
P13M |
If a component contains the largest value, such as 60 for minutes or seconds, SAS normalizes the value and replaces the value with a hyphen. For example, pT12:60:13 becomes PT13:-:13 .
Thirty days is used to normalize a month.
Dates and times in a datetime value that are greater than the standard value for the component are not normalized. They produce an error.
Ending components can contain a fraction that consists of a period or a comma, followed by one to three digits. The following examples show the use of fractions in duration, datetime, and interval values:
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.