HomeContact
How to get today's date in SAS?
September 11, 2021
1 min

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 = 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;```
**"Example":**
```sas
data _null_;
today = today();
put today date9.;
run;

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

Date FormatSAS FormatsExample
DDMMMYYYYdate9.29AUG2021
DD-MM-YYYYddmmyyd10.29-08-2021
DD/MM/YYYYddmmyy10.29/08/2021
“DD”:“MM”: YYYYDDMMYYX.“29”:“08”:2021
DD MM YYYYDDMMYYB10.29 08 2021
DDMMYYYYDDMMYYN8.29082021
DD.MMYYYYDDMMYYP10.29.08.2021
MM/DD/YYYYMMDDYY10.08/29/2021
MM-DD-YYYYmmddyyd10.08-29-2021
MM DD YYYYMMDDYYB10.08 29 2021
“MM”:“DD”: YYYYMMDDYYC10.“08”:“29”:2021
MMDDYYYYMMDDYYP10.08.29.2021
MMDDYYYYMMDDYYN8.08292021
YYYY-MM-DDYYMMDD10.2021-08-29
YYYY/MM/DDYYMMDDS10.2021/08/29
“YYYY”:“MM”: DDYYMMDDC10.“2021”:“08”:29
YYYY.MM.DDYYMMDDP10.2021.08.21
YYYYMMDDYYMMDDN10.20210821
YYYY MM DDYYMMDDB10.2021 08 21
WORDDATEWORDDATE.August 29, 2021
WORDDATXWORDDATX.29 August, 2021
WEEDATEWEEKDATE.Monday, August 29, 2021
WEEKDATX.WEEKDATXMon, 29 Aug 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 “ddmmmyy”:“hh”:“mm”:ss.ss.

data ex;
date=today();
datetime=datetime();
format date date9. datetime datetime20.;
run;
proc print;

img 612f053547fc9

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=;
run;

“Output”:

DateTime="01SEP2021":"12":"30":00```
## **Macro Equivalent to create a data and DateTime variable with any date**
In Macro language, you must use the literal values inside the [%Sysevalf]("https"://www.9to5sas.com/eval-and-sysevalf/) function.
While the [%Eval function]("https"://www.9to5sas.com/eval-and-sysevalf/) 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**
```sas
%put Date = %Sysevalf('01JAN2021'd );
%put DateTime = %Sysevalf('"01JAN2006":"12":"30":00'dt);

“Output”:

DateTime = 1925112600```
### **Using %SYSFUNC, INPUTN and PUTN**
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.
```sas
%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*/

“Output”:

date3 = 01JAN2021
date4 = 01JAN2021```
## Create a Macro Variable with Today’s Date
**You can [create a user-defined macro variable](https) with today's date.** Use the TODAY() or date function within the %SYSFUNC function.
### User-Defined Macro Variables
```sas
%let todaysDate = %sysfunc(today(), date9.);
%let datetime = %sysfunc(datetime(), datetime.);
%put `&todaysDate;`
%put `&datetime;`

“Output”:

"11SEP21":"08":"36":39```
## **Using Call Symput to create a macro variable with today's date.**
Here we are using [CALL SYMPUTX()](https://www.9to5sas.com/call-symput-in-sas/) to create a global macro variable with no trailing spaces. You can use the DATE() function today() function to get the date.
```sas
data _null_;
call symputx('dt', put(date(), date9.), 'g');
call symputx('dt1', put(datetime(), datetime.), 'g');
run;
%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.

“Output”:

"11SEP21":"08":"39":34```
### 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.
```sas
%put "sysdate": `&sysdate;`
%put "sysdate9": `&sysdate9;`
%put "sysday": `&sysday;`
%put "systime": `&systime;`

“Output”:

"sysdate9": 11SEP2021
"sysday": Saturday
"systime": "02":32```
**Using Call Symputx**
```data _null_;
call symputx('dt',put("&sysdate9"d,date9.));
run;
%put &dt.;```
**"Output":**
```01SEP2021```
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](https://documentation.sas.com/doc/en/pgmsascdc/v_006/nlsref/n1tj735aocxmw7n1kfoz1qpdvb9l.htm).
```sas
option timezone='America/Denver';
data _null_;
d1=today();
put d1 nldate.;
run;

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_;
day=today();
put day nldate.;
run;

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 NameExample
Afrikaans_SouthAfrica29 Augustus 2021
Albanian_Albania29 gusht 2021
Arabic_Algeria29 أغسطس, 2021
Arabic_Bahrain29 أغسطس, 2021
Arabic_Egypt29 أغسطس, 2021
Arabic_India29 أغسطس 2021
Arabic_Iraq29 أغسطس, 2021
Arabic_Jordan29 آب, 2021
Arabic_Kuwait29 أغسطس, 2021
Arabic_Lebanon29 آب, 2021
Arabic_Libya29 أغسطس, 2021
Arabic_Morocco29 أغسطس, 2021
Arabic_Oman29 أغسطس, 2021
Arabic_Qatar29 أغسطس, 2021
Arabic_SaudiArabia29 أغسطس, 2021
Arabic_Sudan29 أغسطس, 2021
Arabic_Syria29 آب, 2021
Arabic_Tunisia29 أغسطس, 2021
Arabic_UnitedArabEmirates29 أغسطس, 2021
Arabic_Yemen29 أغسطس, 2021
Basque_Spain2021-08-29
Bengali_India29/08/2021
Bosnian_BosniaHerzegovina29. avgust 2021.
Bulgarian_Bulgaria29.08.21
Byelorussian_Belarus29.08.2021
Catalan_Spain29/08/21
Chinese_China2021年08月29日
Chinese_China2021年08月29日
Chinese_HongKong2021年08月29日
Chinese_Macau2021年08月29日
Chinese_Singapore2021年08月29日
Chinese_Taiwan2021年08月29日
Cornish_UnitedKingdom29/Mye Est/2021
Croatian_BosniaHerzegovina2021. kolovoza 29
Croatian_Croatia2021. kolovoza 29
Czech_CzechRepublic29. srpna 2021
Danish_Denmark29. august 2021
Dutch_Belgium29 augustus 2021
Dutch_Netherlands29 augustus 2021
English_Australia29 August 2021
English_Belgium29 August 2021
English_Botswana29/August/2021
English_CanadaAugust 29, 2021
English_CaribbeanAugust 29, 2021
English_HongKongAugust 29, 2021
English_India29 August 2021
English_Ireland29 August 2021
English_Jamaica29 August 2021
English_MaltaAugust 29, 2021
English_NewZealand29 August 2021
English_Philippines29 August, 2021
English_Singapore29,August,2021
English_SouthAfrica29 August 2021
English_UnitedKingdom29 August 2021
English_UnitedStatesAugust 29, 2021
English_Zimbabwe29,August,2021
Estonian_Estonia29, august 2021
Faroese_FaroeIslands29/august-2021
Finnish_Finland29. elokuuta 2021
French_Belgium29 août 2021
French_Canada29 août 2021
French_France29 août 2021
French_Luxembourg29 août 2021
French_Switzerland29. août 2021
German_Austria29. August 2021
German_Germany29. August 2021
German_Liechtenstein29. August 2021
German_Luxembourg29. August 2021
German_Switzerland29. August 2021
Greek_Cyprus29/08/2021
Greek_Greece29/08/2021
Greenlandic_Greenland29/augustusi/2021
Hebrew_Israel29 אוגוסט 2021
Hindi_India29-08-2021
Hungarian_Hungary2021. augusztus 29.
Icelandic_Iceland29. ágúst 2021
Indonesian_Indonesia29/Agustus/2021
Irish_Ireland29 Lúnasa 2021
Italian_Italy29 agosto 2021
Italian_Switzerland29. agosto 2021
Japanese_Japan2021年08月29日
Kazakh_Kazakhstan29/08/21
Korean_Korea2021년 08월 29일
Latvian_Latvia2021, 29 augusts
Lithuanian_Lithuania2021, rugpjūtis 29
Macedonian_Macedonia29.08.2021
Malay_Malaysia29 Ogos 2021
Maltese_Malta29 ta Awwissu, 2021
Marathi_India29-08-2021
NorwegianBokmal_Norway29. august 2021
NorwegianNynorsk_Norway29. august 2021
Norwegian_Norway29. august 2021
Persian_India29 اوت 2021
Persian_Iran29⁄08⁄2021
Polish_Poland29 sierpnia 2021
Portuguese_Brazil29 de agosto de 2021
Portuguese_Portugal29 de agosto de 2021
Romanian_Romania29 august 2021
Russian_Russia29.08.21
Russian_Ukraine29.08.21
Serbian_BosniaHerzegovina21-08-29
Serbian_Montenegro29.08.2021.
Serbian_Serbia29.08.2021.
SerbianLatin_BosniaHerzegovina29. avgust 2021.
SerbianLatin_Montenegro29. avgust 2021.
SerbianLatin_Serbia29. avgust 2021.
Slovak_Slovakia2021, augusta 29
Slovenian_Slovenia2021, avgust 29
Spanish_Argentina29 de agosto de 2021
Spanish_Bolivia29 de agosto de 2021
Spanish_Chile29 de agosto de 2021
Spanish_Colombia29 de agosto de 2021
Spanish_CostaRica29 de agosto de 2021
Spanish_DominicanRepublic29 de agosto de 2021
Spanish_Ecuador29 de agosto de 2021
Spanish_ElSalvador29 de agosto de 2021
Spanish_Guatemala29 de agosto de 2021
Spanish_Honduras29 de agosto de 2021
Spanish_Mexico29 de agosto de 2021
Spanish_Nicaragua29 de agosto de 2021
Spanish_Panama29 de agosto de 2021
Spanish_Paraguay29 de agosto de 2021
Spanish_Peru29 de agosto de 2021
Spanish_PuertoRico29 de agosto de 2021
Spanish_Spain29 de agosto de 2021
Spanish_UnitedStates29 agosto 2021
Spanish_Uruguay29 de agosto de 2021
Spanish_Venezuela29 de agosto de 2021
Swedish_Swedenden 29 augusti 2021
Tagalog_PhilippinesAgosto 29, 2021
Tamil_India29-08-2021
Telugu_India29-08-21
Thai_Thailand29/08/2021
Turkish_Turkey29 Ağustos 2021
Ukrainian_Ukraine29.08.21
Vietnamese_Vietnam29 tháng tám 2021
values for the LOCALE= System Option

Tags

assign today's date in sasfind today's date in sas

Share


© 2025 9to5sas
AboutContactPrivacyTerms