SAS Dates: Center of Excellence Data Warehousing
SAS Dates: Center of Excellence Data Warehousing
Center of Excellence
Data Warehousing
Dates
Three types of Date Formats commonly used
Calendar Date
Julian Date
SAS Date
Value for a SAS date is the number of days difference from the date of 1st
January 1960.
Dates after 01/01/1960 are positive values while any prior dates are stored as
negative integers.
DateInternal SAS value
25th March 1959 -282
31st December 1959 -1
1st January 1960 0
2nd January 1960 1
25th March 1960 84
1st March 2001 15035
Dates
One format of a date can be displayed as another format easily, by
using pre-set formats.
An important thing to note is that although the way the value prints is
different, the internal value (the number representing the date) does
not change.
Some examples of commonly used formats are given below:
Format Used Result
Date. 01MAR01
Date9. 01MAR2001
Day. 1
Julday. 60
Julian. 01060
Mmddyy. 03/01/01
Month. 3
Monyy. MAR01
Qtr. 1
Year. 2001
Yymmdd. 01-03-01
Yyqr. 2001QI
Dates
Dates Functions
Datejul
DATEJUL(julian-date)
– Converts a Julian date to a SAS date
Example
date=datejul(juldate)
juldate=2002186
date=15526
Datepart
DATEPART(calendar date)
Converts a date extracted through SQL procedure to a SAS date
Example
date=datepart(caldate)
juldate=July 4 2002:11:30:01
date=15526
Dates
Dates Functions
Day
DAY(date)
– Returns a day of the month from the SAS date
Example
cdate=day(date)
date=15526
cdate=4
Month
Month(date)
– Returns the month from the SAS date
Example
cdate=day(date)
cdate=15526
cdate=7
Dates
Dates Functions
Year
YEAR(date)
– Returns the year from the SAS date
Example
cdate=year(date)
date=15526
cdate=2
Timepart
TIMEPART(calendar date)
– Converts a time extracted through SQL procedure to a SAS date
The time gets converted to a running number
Dates
Dates Informats
Dates are read in, using an informat to convert the raw data
from the input file to a SAS date for internal storage
INFORMATs are used to read a variable. The following
INFORMATS are used in case of Dates
DATEw.
– Reads dates in form : ddmmmyy or ddmmmyyyy
Julianw.
– Reads Julian dates in form : yydd or yyyyddd
MMDDYYw.
– Reads dates in form : mmddyy or mmddyyyy
Dates
Dates Formats
FORMATS give SAS special instructions to write a variable or
date
The following FORMATS are used in case of Dates
DATEw.
– Writes SAS value in the form of ddmmmyy
DAYw.
– Writes the day of the month from a SAS date value
Julianw.
– Writes a Julian date form a SAS date value
MMDDYYw.
– Writes SAS date values in form mmddyy
Questions