Previous Page | Next Page

Working with Dates in the SAS System

Review of SAS Tools


Statements

date-variable='ddMMMyy'D;

is an assignment statement that tells SAS to convert the date in quotation marks to a SAS date value and assign it to date-variable. The SAS date constant 'ddMMMyy'D specifies a particular date, for example, '23NOV00'D, and can be used in many SAS statements and expressions, not only assignment statements.

FORMAT date-variable date-format;

tells SAS to format the values of the date-variable using the date-format. A FORMAT statement within a DATA step permanently associates a format with a date-variable.

INPUT date-variable date-informat;

tells SAS how to read the values for the date-variable from an external file. The date-informat is an instruction that tells SAS the form of the date in the external file.


Formats and Informats for Dates

DATE9.

the form of the date-variable is ddMMMyyyy, for example 23NOV2000.

DATE7.

the form of the date-variable is ddMMMyy, for example 23NOV00.

MMDDYY10.

the form of the date-variable is mm/dd/yyyy, for example, 11/23/2000.

MMDDYY8.

the form of the date-variable is mm/dd/yy, for example, 11/23/00.

WORDDATE18.

the form of the date-variable is month-name dd, yyyy, for example, November 23, 2000.

WEEKDATE29.

the form of the date-variable is day-of-the-week, month-name dd, yyyy, for example, Thursday, November 23, 2000.


Functions

WEEKDAY (SAS-date-value)

is a function that returns the day of the week on which the SAS-date-value falls as a number 1 through 7, with Sunday assigned the value 1.

TODAY()

is a function that returns a SAS date value corresponding to the date on which the SAS program is initiated.


System Options

YEARCUTOFF=

specifies the first year of a 100-year span that is used by informats and functions to read two-digit years, and used by formats to display two-digit years. The value that is specified in YEARCUTOFF= can result in a range of years that span two centuries. If YEARCUTOFF=1950, then any two-digit value between 50 and 99 inclusive refers to the first half of the 100-year span, which is in the 1900s. Any two-digit value between 00 and 49 inclusive refers to the second half of the 100-year span, which is in the 2000s. YEARCUTOFF= has no effect on existing SAS dates or dates that are read from input data that include a four-digit year.

Previous Page | Next Page | Top of Page