Informats |
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 |
Reading ISO 8601 Date, Time, and Datetime Values |
SAS reads ISO 8601 dates, times, and datetimes using various informats, and the resulting values are SAS date, time, or datetime values. The following table shows different date, time, and datetime forms and the informats you use to read them:
Date, Time, or Datetime | ISO 8601 Notation | Example | Informat |
---|---|---|---|
Basic Notations | |||
Date | YYYYMMDD | 20080915 | B8601DAw. |
Time | hhmmssnnnnnn | 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 | B8601TZw.d |
Datetime | YYYYMMDDThhmmssnnnnnn | 20080915T155300 | B8601DTw.d |
Datetime with timezone | YYYYMMDDThhmmss+|-hhmm | 20080915T155300+0500 | B8601DZw.d |
|
YYYYMMDDThhmmssZ | 20080915T155300Z |
B8601DZw.d
|
Read the date from a datetime | YYYYMMD | 20080915 | B8601DNw. |
Extended Notations | |||
Date | YYYY-MM-DD | 2008-09-15 | E8601DAw. |
Time | hh:mm:ss.nnnnnn | 15:53:00.322348 | E8601TMw.d |
Time with time zone | hh:mm:ss.nnnnnn+|-hh:mm | 15:53:00+05:00 | E8601TZw.d |
Convert to local time with time zone | hh:mm:ss.nnnnnn+|-hh:mm | 15:53:00+05:00 | E8601LZw.d |
Datetime | YYYY-MM-DDThh:mm:ss.nnnnnn | 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 |
Read date from a datetime | YYYY-MM-DD | 2008-09-15 | E8601DNw. |
Reading ISO 8601 Duration, Interval, and Datetime Values |
SAS uses two informats that reads ISO datetime, duration, and interval values.
reads duration, interval, and datetime values that are specified in either the basic notation or the extended notation
reads duration, interval, and datetime values that are specified only in the extended notation
Use the $N8601E informat when you want to make sure that you are in compliance with the extended notation.
The datetime values that are read by these informats result in a SAS character representation. If you want a datetime value to be read as a numeric value, use the B8601DT informat, the B8601DZ informat, the E8601DT informat, or the E8601DZ informat.
The following table shows the formatting of duration, datetime, and interval values that can be read in the complete form:
One or more date or time components can be omitted from a datetime value or a duration value that is in the form Pyyyymmdd. SAS reads omitted components using the $N8601B informat or the $N8601E informat, and the omitted component must be represented by a hyphen ( - ).
The following examples show duration, datetime, and interval values with omitted components:
The omitted component is the number of days.
The omitted component is the number of hours.
The omitted components are the number of years, minutes, and seconds.
The omitted components are the minutes.
When reading values that contain a time zone offset, omitted components are not allowed. Use 00 in place of omitted components.
SAS reads truncated duration, datetime, and interval values, where one or more lower order components is truncated because the value is 0 or the value is not significant.
The following list shows examples of truncated values:
When reading values that contain a time zone offset, truncation is not allowed. Use 00 in place of 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.