today's date in SAS

How to get today’s date in SAS?

To get today’s date in SAS, you can use the today() or date() functions. These functions return the number of days since January 1, 1960.

To get the current date and time in SAS, use the DATETIME() function. When you use this function, SAS returns the number of seconds between January 1, 1960, and the current time. You must apply a DateTime format to make this value easy to interpret.

For more details on SAS date functions, see our guide on Date Functions in SAS – The Definitive Guide.

Today_date = today(); /* days today is since 1/1/1960 */ 
Today_date = Date(); /* days today is since 1/1/1960 */
Today_datetime = datetime(); /* seconds between January 1, 1960, and the current time.*/

Arithmetic also works in these functions.

Yesterday = today() – 1; 
EndDate = StartDate + 14;


data _null_;    
    today = today();
    put today date9.;

Here are some date formats you can use to display the current date in SAS.

Date Format SAS Formats Example
DDMMMYYYY date9. 29AUG2021
DD-MM-YYYY ddmmyyd10. 29-08-2021
DD/MM/YYYY ddmmyy10. 29/08/2021
DD:MM: YYYY DDMMYYX. 29:08:2021
DD MM YYYY DDMMYYB10. 29 08 2021
DD.MMYYYY DDMMYYP10. 29.08.2021
MM/DD/YYYY MMDDYY10. 08/29/2021
MM-DD-YYYY mmddyyd10. 08-29-2021
MM DD YYYY MMDDYYB10. 08 29 2021
MM:DD: YYYY MMDDYYC10. 08:29:2021
MMDDYYYY MMDDYYP10. 08.29.2021
YYYY-MM-DD YYMMDD10. 2021-08-29
YYYY/MM/DD YYMMDDS10. 2021/08/29
YYYY:MM: DD YYMMDDC10. 2021:08:29
YYYY.MM.DD YYMMDDP10. 2021.08.21
YYYY MM DD YYMMDDB10. 2021 08 21
WORDDATE WORDDATE. August 29, 2021
WORDDATX WORDDATX. 29 August, 2021
WEEDATE WEEKDATE. Monday, August 29, 2021
Date formats in SAS

Create a New SAS Variable with Today’s Date

The today() or date() function can be assigned to a variable in a SAS dataset since SAS dates are represented as the number of days from January 1, 1960. So to view it as a date, apply the desired format.

The DateTime function Writes the DateTime values in the form

data ex;
    format date date9. datetime datetime20.;

proc print;
How to get today's date in SAS?

Create a Date and DateTime variable with any date

Data _null_;
Date =put(Input('01SEP2021' , Date9.),date9.);
DateTime=put(Input('01SEP2021:12:30:00' , DateTime18.),datetime20.);
put date= ;
put datetime=;



Macro Equivalent to create a data and DateTime variable with any date

In Macro language, you must use the literal values inside the %Sysevalf function.

While the %Eval function is used for most of the Macro language’s numeric operations, it also performs character comparisons.

Therefore, the Date, DateTime, and Time that follow the quoted Date and Time values for literals are considered to be characters and not part of the Date and Time values.

Using the %sysevalf function

%put Date = %Sysevalf('01JAN2021'd );
%put DateTime = %Sysevalf('01JAN2006:12:30:00'dt);


Date = 22281
DateTime = 1925112600


Date and Time literals don’t allow flexibility in reading the Date and Time values of different forms into SAS, and you can’t format these SAS Date and Time values.

While In the Data Step, you can use the Input and Put function, it is not possible in Macro.

The %sysfunc macro function utilises most of the data step functions. However, the Input and Put functions are not among them.

Instead, you have to use the InputN and PutN Data Step functions.

%put Date2 = %Sysfunc(inputn(01JAN2021,Date9.)) ; /*Reading SAS date*/
%put date3 = %Sysfunc(putn(%Sysevalf('01JAN2021'd),Date9.)); /*Formatting SAS date*/
%put date4 = %Sysfunc(putn(%Sysfunc(inputn(01JAN2021,Date9.)),Date9.)); /*Formatting SAS date*/


Date2 = 22281
date3 = 01JAN2021
date4 = 01JAN2021

Create a Macro Variable with Today’s Date

You can create a user-defined macro variable with today’s date. Use the TODAY() or date function within the %SYSFUNC function.

User-Defined Macro Variables

%let todaysDate = %sysfunc(today(), date9.);
%let datetime = %sysfunc(datetime(), datetime.);
%put &todaysDate;
%put &datetime;



Using Call Symput to create a macro variable with today’s date.

Here we are using CALL SYMPUTX() to create a global macro variable with no trailing spaces. You can use the DATE() function today() function to get the date.

data _null_;
call symputx('dt', put(date(), date9.), 'g');
call symputx('dt1', put(datetime(), datetime.), 'g');

%put &dt;
%put &dt1;

Since SAS dates are numbers, you need to convert them to characters. Use the PUT function with the format you’d like the date format to appear.



Automatic Macro Variables to get today’s date in SAS

Besides user-defined macro variables, SAS also has automatic macro variables containing the current date.  These macro variables always exist and can be used to get the current date.

The SYSDATE and SYSDATE9 variables contain today’s date. 

The SYSDATE9 contains the current date in the DATE9. format and SYSDATE have the DATE7. format.

The SYSTIME automatic, macro variables will have the date and time the SAS session started.

%put sysdate:  &sysdate;   
%put sysdate9: &sysdate9;  
%put sysday:   &sysday;    
%put systime:  &systime;


sysdate: 11SEP21
sysdate9: 11SEP2021
sysday: Saturday
systime: 02:32

Using Call Symputx

data _null_;
   call symputx('dt',put("&sysdate9"d,date9.));
%put &dt.;



Note that these automatic macro variables are strings. Hence, if you want to use them in a calculation, you must place them between double quotes and the character “d”.

Determining the Current Date for a North America/Denver Time Zone

The TIMEZONE system option specifies the user’s local time zone.

For the list of all timezone, refer here.

option timezone='America/Denver';
data _null_;
    put d1 nldate.;
10 September 2021

Determining the Current Date for an Asia/India Time Zone

Localization is the way data is read on input and how it is formatted and presented on output. This is defined by the setting of the LOCALE system option.

options locale=English_India;
data _null_;
put day nldate.;
10 September 2021

NLDATE Converts the SAS date value to the date value of the specified locale by using the date format descriptors.

The below table lists the values for the LOCALE= System Option.

SAS Name Example
Afrikaans_SouthAfrica 29 Augustus 2021
Albanian_Albania  29 gusht 2021
Arabic_Algeria  29 أغسطس, 2021
Arabic_Bahrain  29 أغسطس, 2021
Arabic_Egypt  29 أغسطس, 2021
Arabic_India  29 أغسطس 2021
Arabic_Iraq  29 أغسطس, 2021
Arabic_Jordan  29 آب, 2021
Arabic_Kuwait  29 أغسطس, 2021
Arabic_Lebanon  29 آب, 2021
Arabic_Libya  29 أغسطس, 2021
Arabic_Morocco  29 أغسطس, 2021
Arabic_Oman  29 أغسطس, 2021
Arabic_Qatar  29 أغسطس, 2021
Arabic_SaudiArabia  29 أغسطس, 2021
Arabic_Sudan  29 أغسطس, 2021
Arabic_Syria  29 آب, 2021
Arabic_Tunisia  29 أغسطس, 2021
Arabic_UnitedArabEmirates  29 أغسطس, 2021
Arabic_Yemen  29 أغسطس, 2021
Basque_Spain  2021-08-29
Bengali_India  29/08/2021
Bosnian_BosniaHerzegovina  29. avgust 2021.
Bulgarian_Bulgaria  29.08.21
Byelorussian_Belarus  29.08.2021
Catalan_Spain  29/08/21
Chinese_China  2021年08月29日
Chinese_China  2021年08月29日
Chinese_HongKong  2021年08月29日
Chinese_Macau  2021年08月29日
Chinese_Singapore  2021年08月29日
Chinese_Taiwan  2021年08月29日
Cornish_UnitedKingdom  29/Mye Est/2021
Croatian_BosniaHerzegovina  2021. kolovoza 29
Croatian_Croatia  2021. kolovoza 29
Czech_CzechRepublic  29. srpna 2021
Danish_Denmark  29. august 2021
Dutch_Belgium  29 augustus 2021
Dutch_Netherlands  29 augustus 2021
English_Australia  29 August 2021
English_Belgium  29 August 2021
English_Botswana  29/August/2021
English_Canada  August 29, 2021
English_Caribbean  August 29, 2021
English_HongKong  August 29, 2021
English_India  29 August 2021
English_Ireland  29 August 2021
English_Jamaica  29 August 2021
English_Malta  August 29, 2021
English_NewZealand  29 August 2021
English_Philippines  29 August, 2021
English_Singapore  29,August,2021
English_SouthAfrica  29 August 2021
English_UnitedKingdom  29 August 2021
English_UnitedStates  August 29, 2021
English_Zimbabwe  29,August,2021
Estonian_Estonia  29, august 2021
Faroese_FaroeIslands  29/august-2021
Finnish_Finland  29. elokuuta 2021
French_Belgium  29 août 2021
French_Canada  29 août 2021
French_France  29 août 2021
French_Luxembourg  29 août 2021
French_Switzerland  29. août 2021
German_Austria  29. August 2021
German_Germany  29. August 2021
German_Liechtenstein  29. August 2021
German_Luxembourg  29. August 2021
German_Switzerland  29. August 2021
Greek_Cyprus  29/08/2021
Greek_Greece  29/08/2021
Greenlandic_Greenland  29/augustusi/2021
Hebrew_Israel  29 אוגוסט 2021
Hindi_India  29-08-2021
Hungarian_Hungary  2021. augusztus 29.
Icelandic_Iceland  29. ágúst 2021
Indonesian_Indonesia  29/Agustus/2021
Irish_Ireland  29 Lúnasa 2021
Italian_Italy  29 agosto 2021
Italian_Switzerland  29. agosto 2021
Japanese_Japan  2021年08月29日
Kazakh_Kazakhstan  29/08/21
Korean_Korea  2021년 08월 29일
Latvian_Latvia  2021, 29 augusts
Lithuanian_Lithuania  2021, rugpjūtis 29
Macedonian_Macedonia  29.08.2021
Malay_Malaysia  29 Ogos 2021
Maltese_Malta  29 ta Awwissu, 2021
Marathi_India  29-08-2021
NorwegianBokmal_Norway  29. august 2021
NorwegianNynorsk_Norway  29. august 2021
Norwegian_Norway  29. august 2021
Persian_India  29 اوت 2021
Persian_Iran  29⁄08⁄2021
Polish_Poland  29 sierpnia 2021
Portuguese_Brazil  29 de agosto de 2021
Portuguese_Portugal  29 de agosto de 2021
Romanian_Romania  29 august 2021
Russian_Russia  29.08.21
Russian_Ukraine  29.08.21
Serbian_BosniaHerzegovina  21-08-29
Serbian_Montenegro  29.08.2021.
Serbian_Serbia  29.08.2021.
SerbianLatin_BosniaHerzegovina  29. avgust 2021.
SerbianLatin_Montenegro  29. avgust 2021.
SerbianLatin_Serbia  29. avgust 2021.
Slovak_Slovakia  2021, augusta 29
Slovenian_Slovenia  2021, avgust 29
Spanish_Argentina  29 de agosto de 2021
Spanish_Bolivia  29 de agosto de 2021
Spanish_Chile  29 de agosto de 2021
Spanish_Colombia  29 de agosto de 2021
Spanish_CostaRica  29 de agosto de 2021
Spanish_DominicanRepublic  29 de agosto de 2021
Spanish_Ecuador  29 de agosto de 2021
Spanish_ElSalvador  29 de agosto de 2021
Spanish_Guatemala  29 de agosto de 2021
Spanish_Honduras  29 de agosto de 2021
Spanish_Mexico  29 de agosto de 2021
Spanish_Nicaragua  29 de agosto de 2021
Spanish_Panama  29 de agosto de 2021
Spanish_Paraguay  29 de agosto de 2021
Spanish_Peru  29 de agosto de 2021
Spanish_PuertoRico  29 de agosto de 2021
Spanish_Spain  29 de agosto de 2021
Spanish_UnitedStates  29 agosto 2021
Spanish_Uruguay  29 de agosto de 2021
Spanish_Venezuela  29 de agosto de 2021
Swedish_Sweden  den 29 augusti 2021
Tagalog_Philippines  Agosto 29, 2021
Tamil_India  29-08-2021
Telugu_India  29-08-21
Thai_Thailand  29/08/2021
Turkish_Turkey  29 Ağustos 2021
Ukrainian_Ukraine  29.08.21
Vietnamese_Vietnam  29 tháng tám 2021
values for the LOCALE= System Option

Every week we'll send you SAS tips and in-depth tutorials



Subhro provides valuable and informative content on SAS, offering a comprehensive understanding of SAS concepts. We have been creating SAS tutorials since 2019, and 9to5sas has become one of the leading free SAS resources available on the internet.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.