SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Reading Date and Time Values
Lesson Summary

This page contains


I. Text Summary

To go to the page where a task, programming feature, or concept was presented, select a link.

In this lesson you learned how SAS software stores date and time values, as well as how to input common date and time expressions using SAS informats. You also saw how SAS date values can be used in computations or as arguments in SAS functions.

How SAS Stores Date and Time Values
SAS software stores date values as numeric SAS date values, which are the number of days from January 1, 1960. SAS time values are the number of seconds since midnight.

Reading Dates and Times Using Informats
Use SAS informats to read date and time expressions and convert them to SAS date and time values.

  • MMDDYYw. reads dates such as: 053090, 05/30/90, or 05 30 1990.
  • DATEw. reads dates such as:  30May1990,  30May90, or  30-May-1990.
  • TIMEw. reads times such as: 17:00, 17:00:01.34, or 2:34.
  • DATETIMEw. reads dates and times such as: 30May1990:10:03:17.2, 30May90 10:03:17.2, or 30May1990/10:03.

Two-digit year values require special consideration. When a two-digit year value is read, SAS software defaults to a year within a 100-year span determined by the YEARCUTOFF= system option. The default value of YEARCUTOFF= is 1920. You can check or reset the value of your session to use a different 100-year span for date informats.

Using Dates and Times In Calculations
Date and time values can be used in equations like other numeric values. In addition to tracking time intervals, SAS date and time values can be a part of SAS functions and complex calculations.

II. Syntax

To go to the page where a statement or option was presented, select a link.

OPTIONS YEARCUTOFF=yyyy;
DATA=
SAS-data-set;

     INFILE raw-data-file;
     INPUT pointer-control variable informat.;
RUN;


III. Sample Program
     options yearcutoff=1920;
     data perm.aprbills;
        infile aprdata;
        input LastName $8. @10 DateIn mmddyy8. 
+1 DateOut
mmddyy8. +1 RoomRate 6. @35 EquipCost 6.; Days=dateout-datein+1; RoomCharge=days*roomrate; Total=roomcharge+equipcost; run; proc print data=perm.aprbills; run;


IV. Points to Remember

  • SAS software makes adjustments for leap years, but not for daylight savings time.

  • The minimum acceptable field width for the TIMEw. informat is 5. If you specify a w value less than 5, you'll receive an error message in the SAS log.

  • The default value of the YEARCUTOFF= option is 1900 or 1920, depending on which release of SAS you are using. When you work with two-digit year data, remember to check the default value of the YEARCUTOFF= option and change it if necessary.

  • The value of the YEARCUTOFF= system option does not affect four-digit year values. Four-digit values are always read correctly.

  • Be sure to specify the proper informat for reading a date value and the correct field width so that the entire value is read.

  • If SAS date values appear in your program output, apply a date format to display them in legible form.


back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement