Populate current date and current datetime in SAS

In order to populate the current date and current datetime in SAS we will be using TODAY() and DATETIME() Function. Current date in SAS is populated using TODAY() function. Current datetime in SAS is populated using DATETIME() Function. we will using an example for each

  • Populate Current date in SAS using TODAY()
  • Populate Current datetime in SAS using DATETIME()

So we will be using EMP_DET Table in our example

Populate current date and current datetime in SAS 1

 

 

Populate current date in SAS using TODAY() Function

SYNTAX – TODAY()

The following statements illustrate the TODAY() function:

Populate current date and current datetime in SAS 1a

Populate current date in SAS – Method 1 (date. Format)

TODAY() function gets the current date in SAS. date. Format converts the current date to required format


data emp_det1; 
set emp_det; 
curr_date1=today(); 
format curr_date1 date.; 
run;

So the resultant table will be

Populate current date and current datetime in SAS 2

 

 

Populate current date in SAS – Method 2 (date9. Format)

TODAY() function gets the current date in SAS.  date9. Format converts the current date to required format


data emp_det1; 
set emp_det; 
curr_date=today(); 
format curr_date date9.; 
run;


So the resultant table will be

Populate current date and current datetime in SAS 3

 

 

Populate current datetime in SAS using DATETIME() Function :

SYNTAX – DATETIME()

The following statements illustrate the DATETIME() function:

Populate current date and current datetime in SAS 3b

DATETIME() function gets the current date in SAS.  datetime20. Format converts the current datetime to required format


data emp_det1; 
set emp_det; 
curr_datetime=datetime(); 
format curr_datetime datetime20.; 
run;

So the resultant table will be

Populate current date and current datetime in SAS 4

 

                                                                                 

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.