Special Topic: SAS Implementation of ISO 8601

Overview

ISO 8601 is a widely used data standard for dates, times, durations, and intervals. The values are stored as text strings. They are formatted in a way that ensures that all of the components are always unambiguous. ISO 8601 is both platform and software independent, which makes it suitable for data interchange.
Many data standards use a simplified subset of ISO 8601 for specifying their own dates, times, and durations. This is true of several CDISC standards, including SDTM.
A complete discussion of ISO 8601 and the CDISC subset of ISO 8601 is beyond the scope of this document. The following tables provide a general idea of what the text strings look like and how to interpret their values. Additional information is in the references.
This list provides a summary of the SAS Clinical Standards Toolkit support of ISO 8601:
  • Consistent with CDISC SDTM guidelines, the SAS Clinical Standards Toolkit does not support the ISO 8601 basic format. This means that the text strings must contain the hyphen delimiter for parts of the dates, and the colon delimiter for parts of the time.
  • The SAS Clinical Standards Toolkit does not support some of the rarely used formats allowed by ISO 8601. The week (W) formats for dates, Julian dates, and extended dates (used to denote years greater than 9999) are not supported.
SAS provides capabilities for processing ISO 8601 text strings that are far beyond those capabilities required by the SAS Clinical Standards Toolkit and CDISC standards.
  • The SAS informats $N8601B. and $N8601E. convert an ISO 8601 text string to a special string called an ISO 8601 entity.
    The ISO 8601 entity is a complex binary value that is stored as a hexadecimal value in a SAS string variable.
    The ISO 8601 entity string is useful for reporting in the ISO 8601 format because it prevents the loss of valuable information from the input ISO 8601 text string.
  • The ISO 8601 entity value should not be confused with the traditional numeric SAS date, time, or datetime value.
  • The ISO 8601 entity should not be used in calculations or comparisons.
  • The CALL IS8601_CONVERT routine can be used to generate traditional numeric SAS dates, times, and datetime values from an ISO 8601 string.
  • For additional information, see the online SAS documentation.

Example ISO 8601 Values

Overview

The tables in this section provide an overview of some commonly used values. It groups the comments based on the ISO 8601 string type.

Dates and Times: Template

Example ISO 8601 Values for Dates and Times: Template
String
Interpretation
Comment
YYYY-MM-DDTHH:MM:SS
A specific date and time
YYYY: Four-digit year.
MM: # of month (01-12).
DD: # of day of month (01-31).
T: What follows is a time in a 24-hour clock.
HH: Hours.
MM: Minutes.
SS: Seconds.

Dates and Times: Full Datetime Examples

Example ISO 8601 Values for Dates and Times: Full Datetime Examples
String
Interpretation
Comment
2009-03-25
March 25, 2009
Year must have four digits.
Month, day, hour, minute, and second each must have two digits. Single-digit values must be preceded by a leading zero.
2009-03-25T22:29:30
March 25, 2009 10:29 and 30 seconds p.m.
T is always required before a time.
Times must always be in military time (for example, 24-hour clock).
Midnight must be written as 00:00. 24:00 is not valid.
The individual parts of a date value must be separated by a hyphen (-).
The individual parts of a time value must be separated by a colon (:).
2009-03-25T22:29:30.333+05:00
March 25, 2009 10:29 and 30.333 seconds p.m. in the time zone GMT + 5 hours
If provided, the time zone must be in HH:MM format. It cannot be truncated or a partial value.
Some values in ISO 8601 formats can have decimal places. Most commonly, this is seen in seconds. The decimal place can be denoted as either a period (.) or a comma (,).
When a time zone is provided, it must be accompanied by a complete date. The date cannot be truncated or a partial value. This is necessary because the 24 global time zones force the date to be considered as part of the time.
2009-03-25T22:29Z
March 25, 2009 10:29 p.m. Zulu time
Z can be used to substitute for times in GMT (or Zulu) time.

Dates and Times: Partial Datetime Examples

One or more components of the date or time are not known. Partial values are denoted by a single -, no matter how many digits are absent. Partial values can be expressed by truncating the missing parts.
Example ISO 8601 Values for Dates and Times: Partial Datetime Examples
String
Interpretation
Comment
-----T22:29
The time 10:29 p.m.
No value for the date is provided.
A time value must always be prefixed by a date value.
In this example, the date value is completely missing, which would be appropriate for time-only fields.
2009
Year 2009.
Trailing values can be truncated when the values are missing.
2009---25
The 25th day of an unknown month in the year 2009.
The month is missing.
If a missing value is embedded in the string, then it must always be denoted by a hyphen (-).
--03-25
The 25th day of March in an unknown year.
Missing year.
--03--T-:15
The 15th minute of an unknown hour of an unknown day of the third month of an unknown year.
Missing year, day, and hour.
2009-03
Month of March 2009.
Trailing partial values can be omitted (truncated).
If time is omitted, then T must also be omitted.
2009-03--T12
The 12th hour of an unknown day in March 2009.
Missing day of month.

Durations: Template

Example ISO 8601 Values for Durations: Template
String
Interpretation
Comment
PnYnMnDTnHnMnS
Duration
A span of time where n is the number of the unit that follows the unit.
P: indicates that the value is a duration (period)
nY: n elapsed years
nM: n elapsed months
nD: n elapsed days
T: the elapsed time in hours, minutes, and seconds
nH: n elapsed hours
nM: n elapsed minutes
nS: n elapsed seconds
Typically, only the units with actual values are given. For example, P0Y1M would be P1M.

Durations: Examples

Example ISO 8601 Values for Durations: Examples
String
Interpretation
Comment
P1D
The span of one day.
Durations always start with P for a period of time.
Units of time that are not known are usually omitted. If time is omitted, then T must also be omitted.
P0000-00-01
The span of zero years + zero months + one day.
Durations can be expressed in an alternative format.
When expressed, the length of time is stored in the same format as date and time, but preceded by a P. Instead of expressing a specific point in time, it expresses a period of time.
P1Y2M3DT4H5M6S
The span of 1 year, 2 months, 3 days, 4 hours, 5 minutes, and 6 seconds.
The units must be in the correct order.
The T is required for all time values, but it should not be specified if no time value is given.

Intervals: Template

Example ISO 8601 Values for Intervals: Template
String
Interpretation
Comment
PnYnMnDTnHnMnS/YYYY-MM-DDTHH:MM:SS
or
YYYY-MM-DDTHH:MM:SS/PnYnMnDTnHnMnS
or
YYYY-MM-DDTHH:MM:SS/PnYnMnDTnHnMnS
or
YYYY-MM-DDTHH:MM:SS/YYYY-MM-DDTHH:MM:SS
Intervals
This is a duration that is anchored to a specific point in time.

Intervals: Examples

Example ISO 8601 Values for Intervals: Examples
String
Interpretation
Comment
2009-03-25T22:29/P1Y
The span of one year starting on March 25, 2009 at 10:29 p.m.
Intervals can express the period of time that starts at a given point in time.
The end time is implied.
P0001-00-00/2009-03-25T22:29
The span of one year ending on March 25, 2009 at 10:29 p.m.
Intervals can express the period of time that ends at a given point in time.
The start time is implied.
2008-03-25/2009-03-25
The span of time between March 25, 2008 and March 25, 2009, which happens to be one year.
Intervals can express the period of time that starts at a given point in time and ends at a given point in time.
The duration value itself is implied.