Previous Page | Next Page

Working with Dates in the SAS System

Learning More

ATTRIB statement

Information about using the ATTRIB statement to assign or change a permanent format can be found in SAS Language Reference: Dictionary.

DATASETS procedure

To assign or change a variable to a permanent format see the DATASETS procedure in Managing SAS Data Libraries.

PUT and INPUT functions

The PUT and INPUT functions can be used for correcting two common errors in working with SAS dates: treating date values that contain letters or symbols as character variables or storing dates written as numbers as ordinary numeric variables. Neither method enables you to use dates in calculations. Information about these functions can be found in SAS Language Reference: Dictionary.

SAS date values

Documentation on informats, formats, and functions for working with SAS date values, SAS time, and SAS datetime values can be found in SAS Language Reference: Concepts. This documentation includes the following date and time information:

  • SAS stores a time as the number of seconds since midnight of the current day. For example, 9:30 am. is 34200. A number of this type is known as a SAS time value. A SAS time value is independent of the date; the count begins at 0 each midnight.

  • When a date and a time are both present, SAS stores the value as the number of seconds since midnight, January 1, 1960. For example, 9:30 am, November 23, 2000, is 1290591000. This type of number is known as a SAS datetime value.

  • SAS date and time informats read fields of different widths. SAS date and time formats can display date variables in different ways according to the widths that you specify in the format name. The number at the end of the format or informat name indicates the number of columns that SAS can use. For example, the DATE9. informat reads up to nine columns (as in 23NOV2000). The WEEKDATE8. format displays eight columns, as in Thursday, and WEEKDATE27. displays 27 columns, as in Thursday, November 23, 2000.

  • SAS provides date, time, and datetime intervals for counting different periods of elapsed time, such as MONTH, which represents an interval from the beginning of one month to the next, not a period of 30 or 31 days.

  • International date, time, and datetime formats.

SYSDATE9

To include the current date in a title, you can use the macro variable SYSDATE9, which is explained in Producing Detail Reports with the PRINT Procedure.

Previous Page | Next Page | Top of Page