How to Use the TODAY Function in SAS (With Examples)


You can use the TODAY function in SAS to generate the current date.

The following examples show how to use the TODAY function in practice.

Example 1: Use TODAY Function to Generate Current Date (Without Formatting)

By default, the TODAY function generates the current date as a numeric SAS date value, which is the number of days since January 1, 1960:

/*create dataset that contains current date*/
data my_data;
    today_date=today();
run;

/*view dataset*/
proc print data=my_data;

The TODAY function generated the value 23135.

Since this article is being written on May 5, 2023, this means it has been 23,135 days since January 1, 1960.

Example 2: Use TODAY Function to Generate Current Date (DDMMYY10. Formatting)

The following code shows how to use the TODAY function to generate the current date using DDMMYY10. formatting:

/*create dataset that contains current date*/
data my_data;
    today_date=today();
    format today_date ddmmyy10.;
    put today_date;
run;

/*view dataset*/
proc print data=my_data;

The TODAY function generated the current date and the ddmmyy10. format option formatted it as 05/05/2023.

Example 3: Use TODAY Function to Generate Current Date (DATE9. Formatting)

The following code shows how to use the TODAY function to generate the current date using DATE9. formatting:

/*create dataset that contains current date*/
data my_data;
    today_date=today();
    format today_date date9.;
    put today_date;
run;

/*view dataset*/
proc print data=my_data;

The TODAY function generated the current date and the date9. format option formatted it as 05MAY2023.

Note that in this tutorial we only illustrated a few ways of how to format a date.

Refer to the SAS documentation page for a complete list of date formats you can use.

Additional Resources

The following tutorials explain how to perform other common tasks in SAS:

How to Add Days to Date in SAS
How to Get Day of Week from Date in SAS
How to Calculate Difference Between Two Dates in SAS

Leave a Reply

Your email address will not be published. Required fields are marked *