Feed Back And Queries

Navigation

SAS Date Functions DATEPART( ) and TIMEPART( )

 

DATEPART( ) and TIMEPART( ) functions are used to extract the date and time values from the SAS date-time value respectively.

 

One need to provide the date-time stamp as an argument to these function, then the corresponding function will return the desired part of the given date-time stamp.

 
This has been demonstrated below;
 
 
 
 
SAS DATEPART( ) and TIMEPART( ) Functions
 
SYNTAX: 

DATEPART(sasdate_time_value);

TIMEPART(sasdate_time_value);

 
 

Example: SAS DATEPART ( ) and TIMEPART ( ) Functions

SAS Code:
 
 

data temp;

date_time = "19DEC2010:20:10:10"dt;

date_part = datepart(date_time);

time_part = timepart(date_time);

run;

 
proc print data = temp;

format date_part date9. date_time datetime25.6 time_part time.;

run;

 
 
PROC PRINT OUTPUT :
 

Obs

date_time

date_part

time_part

1

19DEC2010:20:10:10.000000

19DEC2010

20:10:10

 
 
 
 * Please note this code has compiled on SAS 9.2 Platform.
 
 
It is worth to note that the output shown above is in corresponding formats just because of formats applied in format statement under PROC PRINT. Otherwise SAS internally stores all those values as numbers only.

 

Comments