Chapter Contents |
Previous |
Next |
Definitions |
The following figure shows some dates written in calendar form and as SAS date values.
How SAS Converts Calendar Dates to SAS Date Values
Two-Digit and Four-Digit Years |
SAS software can read two-digit or four-digit year values. If SAS encounters a two-digit year, the YEARCUTOFF= option can be used to specify which century within a 100 year span the two-digit year should be attributed to. For example, YEARCUTOFF=1950 means that two-digit years 50 through 99 correspond to 1950 through 1999, while two-digit years 00 through 49 correspond to 2000 through 2049. Note that while the default value of the YEARCUTOFF= option in Version 8 of the SAS System is 1920, you can adjust the YEARCUTOFF= value in a DATA step to accomodate the range of date values you are working with at the moment. To correctly handle 2-digit years representing dates between 2000 and 2099, you should specify an appropriate YEARCUTOFF= value between 1901 and 2000. See the How to Read Two-Digit Years Using YEARCUTOFF= section for more information on the YEARCUTOFF= system option.
The Year 2000 |
options yearcutoff=1950; data _null_; a='26oct02'd; put 'SAS date='a; put 'formatted date='a date9.; run;The PUT statement writes the following lines to the SAS log:
SAS date=15639 formated date=26OCT2002
Note: Whenever possible, specify a year using all four
digits. Most SAS date and time language elements support four digit year values.
Working with SAS Dates and Times |
To do this ... | Use this ... | List | Input | Result |
---|---|---|---|---|
Write SAS date values in recognizable forms | Date formats | DATEw. | 14686 | 17MAR00 |
DATE9. | 14686 | 17MAR2000a |
||
DAYw. | 14686 | 17 | ||
DDMMYYw. | 14686 | 17/03/00 | ||
DDMMYY10. | 14686 | 17/03/2000 | ||
DDMMYYBw. | 14686 | 17 03 00 | ||
DDMMYYB10. | 14686 | 17 03 2000 | ||
DDMMYYCw. | 14686 | 17:03:20 | ||
DDMMYYC10. | 14686 | 17:03:2000 | ||
DDMMYYDw. | 14686 | 17-03-00 | ||
DDMMYYD10. | 14686 | 17-03-2000 | ||
DDMMYYNw. | 14686 | 17MAR00 | ||
DDMMYYN10 | 14686 | 17MAR2000 | ||
DDMMYYPw. | 14686 | 17.03.00 | ||
DDMMYYP10. | 14686 | 17.03.2000 | ||
DDMMYYSw. | 14686 | 17/03/00 | ||
DDMMYYS10. | 14686 | 17/03/2000 | ||
DOWNAME. | 14686 | Friday | ||
EURDFDEw. | 14686 | 17MAR00 | ||
EURDFDE9. | 14686 | 17MAR2000 | ||
EURDFDNw. | 14686 | 5 | ||
EURDFDWNw. | 14686 | Friday | ||
EURDFMYw. | 14686 | MAR00 | ||
EURDFDMY7 | 14686 | MAR2000 | ||
EURDFWDXw. | 14686 | 17MAR2000 | ||
EURDFMNw. | 14686 | March | ||
EURDFWKXw. | 14686 | Friday, 17 MAR 2000 | ||
JULDAYw. | 14686 | 77 | ||
JULIANw. | 14686 | 00077 | ||
MINGUOw. | 14686 | 89/03/17 | ||
MINGUO10. | 14686 | 0089/03/17 | ||
MMDDYYw. | 14686 | 03/17/00 | ||
MMDDYY10. | 14686 | 03/17/2000 | ||
MMDDYYBw. | 14686 | 03 17 00 | ||
MMDDYYB10.w. | 14686 | 03 17 2000 | ||
MMDDYYCw. | 14686 | 03:17:00 | ||
MMDDYYC10 | 14686 | 03:17:2000 | ||
MMDDYYDw. | 14686 | 03-17-00 | ||
MMDDYYD10. | 14686 | 03-17-2000 | ||
MMDDYYNw. | 14686 | 031700 | ||
MMDDYYN10. | 14686 | 03172000 | ||
MMDDYYP | 14686 | 03.17.00 | ||
MMDDYYP10. | 14686 | 03.17.2000 | ||
MMDDYYS | 14686 | 03/17/00 | ||
MMDDYYS10. | 14686 | 03/17/2000 | ||
MMYY.xw. | 14686 | 03M2000 | ||
MMYYCw. | 14686 | 03:2000 | ||
MMYYD. | 14686 | 03-2000 | ||
MMYYN. | 14686 | 032000 | ||
MMYYP. | 14686 | 03.2000 | ||
MMYYS. | 14686 | 03/2000 | ||
MONNAME. | 14686 | March | ||
MONTH. | 14686 | 3 | ||
MONYY. | 14686 | MAR2000 | ||
NENGO. | 14686 | H.12/03/17 | ||
PDJULGw. | 14686 | 2000077F | ||
PDJULIw. | 14686 | 0100077F | ||
QTRw. | 14686 | 1 | ||
QTRRw. | 14686 | I | ||
TIMEw.d | 14686 | 4:04:46 | ||
TIMEAMPMw.d | 14686 | 4:04:46 AM | ||
TOD | 14686 | 4:04:46 | ||
WEEKDATEw. | 14686 | Friday, March 17, 2000 | ||
WEEKDAYw. | 14686 | 6 | ||
WORDDATE.w. | 14686 | March 17, 2000 | ||
WORDDATXw. | 14686 | 17 MARCH 2000 | ||
YEARw. | 14686 | 2000 | ||
YYMMw. | 14686 | 2000M03 | ||
YYMMCw. | 14686 | 2000:03 | ||
YYMMDDw. | 14686 | 2000-03 | ||
YYMMPw. | 14686 | 2000.03 | ||
YYMMS. | 14686 | 2000/03 | ||
YYMMN. | 14686 | 200003 | ||
YYMMDDw. | 14686 | 00-03-17 | ||
YYMON. | 14686 | 2000MAR | ||
YYQxw. | 14686 | 2000Q1 | ||
YYQCw. | 14686 | 2000:1 | ||
YYQDw. | 14686 | 2000-1 | ||
YYQPw. | 14686 | 2000.1 | ||
YYQSw. | 14686 | 2000/1 | ||
YYQNw. | 14686 | 20001 | ||
YYQRw. | 14686 | 2000QI | ||
YYQRCw. | 14686 | 2000:I | ||
YYQRDw. | 14686 | 2000-I | ||
YYQRPw.w. | 14686 | 2000.I | ||
YYQRSw. | 14686 | 2000/I | ||
YYQRNw. | 14686 | III |
To do this ... | Use this ... | List | Input | Result |
---|---|---|---|---|
Date Tasks | ||||
Read calendar dates as SAS date Note: YEARCUTOFF=1920 |
Date informats | DATEw. | 17MAR2000 | -14534 |
DATE9. | 17MAR2000 | 14686 | ||
DDMMYYw. | 170300 | 14686 | ||
DDMMYY8. | 17032000 | 14686 | ||
JULIANw. | 0077 | 14686 | ||
JULIAN7. | 2000077 | 14686 | ||
MMDDYYw. | 031700 | 14686 | ||
MMDDYY10. | 03172000 | 14686 | ||
MONYYw. | MAR00 | 14670 | ||
NENGOw. | H.12/03/17 | 14686 | ||
YYMMDDw. | 000317 | 14686 | ||
YYMMDD10. | 20000317 | 14686 | ||
YYQw. | 00Q1 | 14610 | ||
Create date values from pieces | Date functions | DATEJUL | 2000077 | 14686 |
DHMS | '17MAR2000'D, 00,00,00 |
14686 | ||
HMS | 14,45,32 | 53132 | ||
MDY | 03,17,00 | 14686 | ||
MDY | 03,17,2000 | 14686 | ||
YYQ | 00,1 | 14610 | ||
Extract a date from a datetime value | Date functions | DATEPART | '17MAR00:00:00 'DT |
14686 |
Return today's date as a SAS date | Date functions | DATE() or TODAY() (equivalent) | ( ) | SAS date for today |
Extract calendar dates from SAS | Date functions | DAY | 14686 | 17 |
HOUR | 14686 | 4 | ||
JULDATE | 14686 | 0077 | ||
JULDATE7 | 14686 | 2000077 | ||
MINUTE | 14686 | 4 | ||
MONTH | 14686 | 3 | ||
QTR | 14686 | 3 | ||
SECOND | 14686 | 46 | ||
WEEKDAY | 14686 | 6 | ||
YEAR | 14686 | 2000 | ||
Write a date as a constant in an expression | SAS date constant | 'ddmmmyy'd or 'ddmmmyyyy' |
'17mar00'd '17mar2000'd |
14686 |
Write today's date as a string | SYSDATE automatic macro variable | SYSDATE | &SYSDATE | Date at time of SAS initialization in DDMMMYY |
SYSDATE9 | SYSDATE9 | &SYSDATE9 | Date at time of SAS initialization in DDMMMYYYY | |
Time Tasks | ||||
Write SAS time values as time values | time formats | HHMM. | 53132 | 14:46 |
HOUR. | 53132 | 15 | ||
MMSS. | 53132 | 885 | ||
TIME. | 53132 | 14:45:32 | ||
TOD. | 53132 | 14:45:32 | ||
Read time values as SAS time values | Time informats | TIME | 14:45:32 | 53132 |
Write the current time as a string | SYSTIME automatic macro variable | SYSTIME | &SYSTIME | Time at moment of execution in HH:MM |
Return the current time of day as a SAS time value | Time functions | TIME( ) | ( ) | SAS time value at moment of execution in NNNNN.NN |
Return the time part of a SAS datetime value | Time functions | TIMEPART | SAS datetime value in NNNNNNNNNN.N | SAS time value part of date value in NNNNN.NN |
Datetime Tasks | ||||
Write SAS datetime values as datetime values | Datetime formats | DATEAMPM | 1217083532 | 26JUL98:02:45 PM |
DATETIME | 1268870400 | 17MAR00:00:00 :00 |
||
EURDFDT | 1217083532 | 26JUL98:14:45:32 | ||
Read datetime values as SAS datetime values | Datetime informats | DATETIME | 17MAR00:00:00:00 | 1268870400 |
Return the current date and time of day as a SAS datetime value | Datetime functions | DATETIME() | () | SAS datetime value at moment of execution in NNNNNNNNNN.N |
Interval Tasks | ||||
Return the number of specified time intervals that lie between the two date or datetime values | Interval functions | INTCK | week 2 01aug60 01jan01 |
1055 |
Advances a date, time, or datetime value by a given interval, and returns a date, time, or datetime value | Interval functions | INTNX | day 14086 01jan60 |
14086 |
Examples |
Note:
data test; options nodate pageno=1 linesize=80 pagesize=60; Time1=86399; format Time1 datetime.; Date1=86399; format Date1 date.; Time2=86399; format Time2 timeampm.; run; proc print data=test; title 'Same Number, Different SAS Values'; footnote1 'Time1 is a SAS DATETIME value'; footnote2 'Date1 is a SAS DATE value'; footnote3 'Time2 is a SAS TIME value'.; run;
Datetime, Date and Time Values for 86399
Same Number, Different SAS Values 1 Obs Time1 Date1 Time2 1 01JAN60:23:59:59 20JUL96 11:59:59 PM Time1 is a SAS DATETIME value Date1 is a SAS DATE value Time2 is a SAS TIME value. |
data meeting; options nodate pageno=1 linesize=80 pagesize=60; input region $ mtg : mmddyy8.; sendmail=mtg-45; datalines; N 11-24-99 S 12-28-99 E 12-03-99 W 10-04-99 ; proc print data=meeting; format mtg sendmail date9.; title 'When To Send Announcements'; run;
Calculated Date Values: When to Send Mail
When To Send Announcements Obs region mtg sendmail 1 N 24NOV1999 10OCT1999 2 S 28DEC1999 13NOV1999 3 E 03DEC1999 19OCT1999 4 W 04OCT1999 20AUG1999 |
International Date, Time and Datetime Formats |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.