Download presentation
Presentation is loading. Please wait.
1
ISO 8601 and SAS ®: A Practical Approach
Derek Morgan PAREXEL International
2
Section 1: What Is ISO 8601?
3
The ISO 8601 Standard Internationally accepted methodology describing dates and times using numbers Standard covers: Dates Time of day Date and time Coordinated Universal Time (UTC) Local time with offset to UTC Time intervals and recurring time intervals
4
The ISO 8601 Standard Removes problems of: Translation
August can be expressed as “août”; “август”; “agosto”; “八月” Local norms for expressing dates Is it March 8, 2016 or August 3, 2016?
5
Basic vs. Extended Notation
Basic is just the numbers Extended uses delimiters Basic Notation Extended Notation 2016 201606 T1422 T14:22 T142237 T14:22:37 T T14:22:37.74
6
Section 2: SAS ® and ISO 8601
7
A Few Basics SAS maintains dates and times as numbers relative to a reference point Needs an exact number ISO 8601 allows for missing components In standard SAS dates and times, missing components=missing value SAS can handle ISO dates with missing components Separate from normal SAS dates and times if you need it
8
Reading Extended Notation ISO 8601 Dates and Times into SAS ®
Use informats - No different than any other complete SAS date, time or datetime Create a SAS datetime from an ISO 8601 datetime: xxxdtm = INPUT(xxDTC,E8601DT.); Create a SAS date from an ISO 8601 date (or datetime): xxxdt = INPUT(xxDTC,E8601DA.); BUT pick the time from the complete SAS datetime created above xxxtm = TIMEPART(xxxdtm);
9
Reading Basic Notation ISO 8601 Dates and Times into SAS ®
The informats for basic notation begin with the letter “B” Create a SAS datetime with B8601DT. Create a SAS date with B8601DA. STILL pick the time from the complete SAS datetime you created using TIMEPART() WARNING!!! Basic notation informats will substitute 0 for missing time components, and 1 for missing day or month components!
10
Basic vs. Extended Notation Informats
ISO 8601 Character String Read with E8601DT. Read with B8601DT. T16:14 26MAR2014:16:14:00 24JUN2014:00:00:00 01SEP2014:00:00:00 You may wind up with an unexpected imputation using the basic notation informat!
11
Writing ISO 8601 Dates and Times in SAS ® the Normal Way
Use formats - No different than any other complete SAS date, time or datetime. IF dt_value is a valid SAS datetime value: vsdtc = PUT(dt_value,E8601DT.) creates an ISO 8601 datetime vsdt = PUT(dt_value,E8601DN.) creates an ISO 8601 date from a datetime vstm = PUT(TIMEPART(dt_value),E8601TM.)
12
Writing ISO 8601 Dates and Times in SAS ® the Normal Way
IF dt_value is a valid SAS date: vsdt = PUT(dt_value,E8601DA.) creates an ISO 8601 date
13
SAS ® ISO 8601 Facility Stored internally in CHARACTER variables
Needs CHARACTER formats and informats to make any sense, just like normal dates and times Can accommodate missing components Can perform simple, automatic imputation in calculations This may not be what you want Recommend doing any imputation before using this for calculations
14
How SAS ® Stores ISO 8601 Values
Original ISO String SAS Datetime Value Formatted SAS Datetime Value SAS ISO Internal Value T15:05:30 20APR2015:15:05:30 FFD T06:40 22DEC2016:06:40:00 2016C220640FFFFD FFFFFFFFD 20159FFFFFFFFFFD T02 FFFFFFD 2016 2016FFFFFFFFFFFD
15
ISO 8601 Durations and Intervals
Duration describes a period of time: PT17H41M P2DT10H30M Intervals describe start and end of a period 3 Forms: Datetime/Datetime: T17:19/ T11:00 Datetime/Duration: T17:19/P0Y0M0DT17H41M0S Duration/Datetime: P0Y0M0DT17H41M0S/ T11:00
16
How Do You Calculate ISO Durations and Intervals?
Divide end date-start date by several factors to get years, months, days, hours, etc. - or - Use the SAS interval function INTCK() to get years, months, days, hours, etc. Concatenate the results with the appropriate delimiters
17
There’s An Easier Way DATA duration1; SET full_datetimes; LENGTH aedur $ 32; CALL IS8601_CONVERT('dt/dt','du', aestdtm,aeendtm,aedur); FORMAT aedur $N8601E.; RUN; Event Start Date/Time Event End Date/Time Duration 22DEC2016:00:00:00 23DEC2016:00:00:00 P1D 15JAN2014:00:00:00 04JUN2014:00:00:00 P4M20D 25FEB2013:00:00:00 16MAY2017:00:00:00 P4Y2M19D
18
The IS8601_CONVERT Routine
Syntax: CALL IS8601_CONVERT(convert-from, convert-to, <from-variables>, <to-variables>, <date-time-replacements>); Works with SAS ISO datetimes and SAS datetimes, interchangeably.
19
And That’s the Practical of it...
The ISO 8601 standard is an internationally accepted methodology describing dates and times using numbers There are informats to read ISO 8601 dates and times There are formats to write ISO 8601 dates and times SAS can handle missing components in ISO 8601 dates and times - separate facility from normal dates and times The IS8601_CONVERT routine calculates ISO durations easily
20
Any Questions? References:
Harnessing the Power of SAS® ISO 8601 Informats, Formats, and the CALL IS8601_CONVERT Routine; Kim Wilson, SAS Institute Inc., Cary, NC, USA, PharmaSUG 2012 The Essential Guide to SAS® Dates and Times, Second Edition. Cary, NC: SAS Institute Inc.; Morgan, Derek P And that's it.
21
Derek Morgan, PAREXEL International
Thank You! Derek Morgan, PAREXEL International
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.