If you work with dates in SAS, you often need today’s date.
But, how do you get today’s date in SAS? In SAS, both the TODAY() function and the DATE() function give you the current date. These functions will return the number of days between the 1st of January 1960 and today. So, to make them appear as a date, you have to apply a format.
In this article, we demonstrate how you can use these functions.
Contents
Print Today’s Date to the SAS Log
You can use the TODAY() or DATE() function in combination with a _NULL_ dataset to print today’s date to the SAS log.
In the examples below, we show how to generate the current date, apply the most used SAS date formats, and print the result to the log.
Today’s Date in DDMMMYYYY Format
data _null_; my_date = today(); format my_date date9.; put "Current Date (formatted as DDMMMYYYY): " my_date; run;

Today’s Date in MM-DD-YYYY Format
data _null_; my_date = today(); format my_date mmddyyd10.; put "Current Date (formatted as MM-DD-YYYY): " my_date; run;

Today’s Date in MM/DD/YYYY Format
data _null_; my_date = today(); format my_date mmddyy10.; put "Current Date (formatted as MM/DD/YYYY): " my_date; run;

Today’s Date in DD-MM-YYYY Format
data _null_; my_date = today(); format my_date ddmmyyd10.; put "Current Date (formatted as DD-MM-YYYY): " my_date; run;

Today’s Date in DD/MM/YYYY Format
data _null_; my_date = today(); format my_date ddmmyy10.; put "Current Date (formatted as DD/MM/YYYY): " my_date; run;

Today’s Date in Worddate Format
data _null_; my_date = today(); format my_date worddate.; put "Current Date: " my_date; run;

Today’s Date in Weekdate Format
data _null_; my_date = today(); format my_date weekdate.; put "Current Date: " my_date; run;

Create a New SAS Variable with Today’s Date
You can also use the TODAY() or DATE() function to create a new SAS variable. For example, with the code below, we create a new SAS dataset with 5 rows where the column date_column contains the current date.
data work.my_ds; do i = 1 to 5; some_text = "Today's date is:"; date_column = today(); output; end; format date_column date9.; drop i; run;

In the example above, we created a new variable with the current date. SAS offers also the MDY() function to create dates. Read this post to learn more about the MDY() function.
For more, general information about creating new variable, read this post.
Use Today’s Date in a SAS Function
You can also use the TODAY() or DATE() function as part of another function (a so-called nested function). For example, here we calculate the number of days between a given date (i.e., start) and today’s date.
data work.my_ds; start = "01JAN2020"D; today = today(); diff_in_days = intck("day", start, today); output; start = "04FEB2020"D; today = today(); diff_in_days = intck("day", start, today); output; start = "13SEP2020"D; today = today(); diff_in_days = intck("day", start, today); output; start = "01JAN2021"D; today = today(); diff_in_days = intck("day", start, today); output; format start today date9.; run;

In the example above, we used the INTCK() function to calculate the difference between two dates. This isn’t its only functionality. The INTCK() function is a very powerful function with lots of uses. Read our other post to get the most out of this function.
Create a Macro Variable with Today’s Date
Finally, you can also get the current date in a macro variable. For this, you need to write the TODAY() function within the %SYSFUNC function.
%let my_date_no_format = %sysfunc(today()); %put &=my_date_no_format.;

As the example above shows, the result of the TODAY() function is saved as a macro variable, but it isn’t easily interpretable as a date. So, we need to apply a SAS date format. In the code below, we apply the date9. format to the macro variable with the current date.
%let my_date_formatted = %sysfunc(today(), date9.); %put &=my_date_formatted.;
