Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

SAS Date Times date time


May 27, 2021 SAS


Table of contents


Dates in SAS are calculated in a special way, with January 1, 1960 as the center point, with a date of 0, a date of 1 for the next date, and so on. T he date before this date is a negative number of -1, -2, etc. Using this method, SAS can represent any future date and any date in the past.

When SAS reads data from a source, it converts the read data to a specific date format in the specified date format. T he variable used to store the date value is declared using the correct informat required. The output date is displayed by using the output data format.

SAS date information

The source data can be read correctly with specific date information, as shown below. T he number at the end of the information represents the minimum width of the date string that is fully read using the information. A smaller width will give incorrect results. W ith SAS V9, there is a common date format anydtdte15. I t can handle any date input.

Enter the date The width of the date INFORMAT
03/11/2014 10 mmddyy10。
03/11/14 8 mmddyy8。
December 11, 2012 20 worddate20。
14mar2011 9 date9。
14-mar-2011 11 date11。
14-mar-2011 15 anydtdte15。

Cases

The following code shows reads in different date formats. N ote that all output values are just numbers because we do not apply any format statements to the output values.

DATA TEMP;
INPUT @1 Date1 date11. @12 Date2 anydtdte15. @23 Date3 mmddyy10.   ;
DATALINES;
02-mar-2012 3/02/2012 3/02/2012
;
PROC PRINT DATA=TEMP;
RUN;

When executing the above code, we can get the following output.

SAS Date Times date time

SAS data output format

The read date can be converted to a different format based on the requirements of the display. T his is implemented using a format statement of the date type. T hey are in the same format as informats.

Cases

In the following example, the date is read in one format, but displayed in another format.

DATA TEMP;
INPUT  @1 DOJ1 mmddyy10. @12 DOJ2 mmddyy10. ;
format  DOJ1 date11.  DOJ2 worddate20. ;
DATALINES;
01/12/2012 02/11/1998 
;
PROC PRINT DATA=TEMP;
RUN;

When executing the above code, we can get the following output.

SAS Date Times date time