Table of Contents

 

 

Acknowledgments....................................................................................................... vii

1     Introduction to Dates and Times in SAS........................................................ 1

       1.1  How Does It Work? (January 1, 1960 and Midnight as Zero)............................. 2

       1.2  Internal Representation (Storage as Integers or Real Numbers)............................ 2

       1.3  External Representation (Basic Format Concepts)................................................ 3

       1.4  Date and Time as Numeric Constants in SAS..................................................... 3

       1.5  System Options Related to Dates...................................................................... 5

       1.6  Length and Numeric Requirements for Date, Time, and Datetime....................... 12

 

2     Displaying SAS Date, Time, and Datetime Values as Dates and Times
       as We Know Them........................................................................................ 15

       2.1  How Do I Use a Format?............................................................................... 16

       2.2  So Just How Many Built-in Formats Are There for Dates and Times?.................... 18

       2.3  A Quick Note About Date Formats, Justification, and ODS................................ 19

       2.4  Detailed Discussion of Each Format................................................................ 19

       2.4.1  Date Formats..................................................................................... 19

       2.4.2  Time Formats..................................................................................... 43

       2.4.3  Datetime Formats............................................................................... 47

       2.5  Creating Custom Date Formats Using the VALUE Statement of
                   PROC FORMAT........................................................................................... 54

       2.6  Creating Custom Date Formats Using the PICTURE Statement of
                   PROC FORMAT........................................................................................... 56

       2.7  The PUT() Function and Formats..................................................................... 60

 


3     Converting Dates and Times into SAS Date, Time,
       and Datetime Values..................................................................................... 63

       3.1  Avoiding the Two-Digit Year Trap.................................................................. 64

       3.2  Using Informats............................................................................................ 65

       3.3  The INFORMAT Statement............................................................................. 66

       3.3.1  Using Informats with the INPUT Statement............................................. 66

       3.3.2  Informats with the INPUT() Function...................................................... 67

       3.3.3  When the Informat Does Not Match the Data Being Read...................... 68

       3.4  Listing and Discussion of Informats.................................................................. 70

       3.4.1  Date Informats................................................................................... 70

       3.4.2  Time Informats................................................................................... 75

       3.4.3  Datetime Informats............................................................................. 77

       3.4.4  ANYDT and Its Variants...................................................................... 77

 

4     Date and Time Functions............................................................................... 85

       4.1  Current Date and Time Functions.................................................................... 86

       4.2  Extracting Pieces from SAS Date, Time, and Datetime Values............................ 86

       4.3  Creating Dates, Times, and Datetimes from Numbers....................................... 89

       4.4  Calculating Intervals..................................................................................... 93

       4.4.1  Calculating Elapsed Time with DATDIF() and YRDIF()............................ 93

       4.4.2  The Basics of SAS Intervals.................................................................. 96

       4.4.3  The Interval Calculation Functions: INTCK and INTNX............................ 98

 

5     Deeper into Dates and Times with SAS..................................................... 107

       5.1  Macro Variables and Dates........................................................................ 108

       5.1.1  Automatic Macro Variables............................................................... 108

       5.1.2  Putting Dates into Titles..................................................................... 109

       5.1.4  Using %SYSFUNC() to Create Dates, Times, and Datetimes in
                 Macro Variables.............................................................................. 110

       5.1.4  Using CALL SYMPUT() and SYMGET() with Dates, Times, and
                 Datetimes........................................................................................ 111

       5.2  Shifting SAS Date and Time Intervals............................................................ 113

       5.3  Graphing Dates........................................................................................ 122


       5.4  The Basics of PROC EXPAND...................................................................... 127

       5.4.1  Capabilities of PROC EXPAND.......................................................... 127

       5.4.2  Using PROC EXPAND to Convert to a Higher Frequency....................... 129

       5.4.3  Using PROC EXPAND to Convert to a Lower Frequency........................ 130

       5.4.4  Using PROC EXPAND to Interpolate Missing Values............................. 132

       5.4.5  The OBSERVED= Option for the CONVERT Statement in
                 PROC EXPAND............................................................................... 133

       5.5  International Date, Time, and Datetime Formats and Informats........................ 136

       5.5.1  “EUR” Formats and Informats............................................................ 137

       5.5.2  “NL” Formats................................................................................... 140

       5.5.3  Specific Language Date Formats and Informats................................... 143

       5.6  Other Software and Their Dates (Excel, Oracle, DB2).................................... 144

 

Appendix  A Quick Reference Guide to SAS Date, Time, and Datetime
                 Formats............................................................................................... 145

Index.................................................................................................................... 147