Rabidwolff's Alehouse
"Your place for fun and knowledge."
HOME | Quotes | SAS | C# | BEER



Basics
FORMATS
INFORMATS
DATETIME
ATTRIB
LENGTH
FORMAT
INFORMAT
LABEL
JOINS
OPERATORS

Statements
RETAIN
FIRST.
LAST.

Procedures
PROC SORT
PROC COPY
PROC CPORT
IF ELSE
PROC REPORT

Functions
CAT
CATS
CATT
CATX

CDISC
Random Q & A

CDISC
CDISC Info

Coded Tools
XML Output
Examples

DATETIME

Contents

  1. The Basics
  2. DATE, TIME, or DATETIME Variable Constants
  3. Use of Two Digit Years Explained
  4. Common Date/Time Formats Used

The Basics

  1. SAS DATE fields hold the number of days from 01JAN1960
  2. SAS TIME fields hold the number of seconds since midnight of the current day, up to 86400
  3. SAS DATETIME fields hold the number of seconds since midnight of 01JAN1960 to the current date and time specified
  4. The format only shows how to display the value

DATE, TIME, or DATETIME Variable Constants

SAS has a special assignment statement to allow a DATE, TIME, or DATETIME to be saved to a variable. The entered information but confirm to the specified INFORMAT. A FORMAT can then be applied to control how the variable is displayed.

Examples Explained:
Type InFormat Applied Example Input Code Example Format Applied Code Example Output Value
DATE ddMMM<yy>yy DATE1= '01JAN2012'd; DATE1 format DATE9.; 01JAN2012
DATE ddMMM<yy>yy DATE1= '1JAN12'd; DATE1 format DATE9.; 01JAN2012
TIME hh:mm<:ss.s> TIME1= '16:34't; TIME1 format TIME5.; 16:34
TIME hh:mm<:ss.s> TIME2= '1:1:3.6pm't; TIME2 format TIME12.2; 13:01:03.60
DATETIME ddmmm<yy>yy:hh:mm<:ss.s> DT1= '01JAN2012:2:3:4.56pm'dt; format DT1 DATETIME22.3; 01JAN2012:14:03:04.560
DATETIME ddmmm<yy>yy:hh:mm<:ss.s> DT2= '01JAN12:3:0 am'dt; format DT2 DATETIME22.3; 01JAN2012:03:00:00.000

Use of Two Digit Years Explained

SAS assumes the 4 digit year when a 2 digit year is saved. SAS uses a YEARCUTOFF= option to determine the 4 digit year. The default is 1920 for SAS version 8.0+. This means that any year 2 digit year entered 50-99 are saved as 1950-1999 while 00-20 are saved as 2000-2020.

Changing the YEARCUTOFF= option to 1975, for example, would mean any 2 digit date 75-99 is saved as 1975-1999 while 00-74 is saved as 2000-2074.

Example Code:


Output Variables:
DATE1= 01JAN2074
DATE2= 01JAN1975
DATE3= 01JAN1976
DATE4= 01JAN1999
DATE5= 01JAN2000
DATE6= 01JAN2001

Common Date/Time Formats Used

  • DATE9.
  • MMDDYY6.
  • MMDDYY8.
  • MMDDYY10.
  • WORDDATE20.
  • DATETIME20. = ddmmmyy:hh:mm:ss.ss
  • TIME5. = hh:mm
  • TIME11. = hh:mm:ss.ss
  • TOD

Rabidwolff Industries | Establisted: 10/15/2011 | Version: 4 8/4/2012 | Page Last Generatated: 9/25/2021 4:30:35 PM