SAS Date Functions DATEPART( ) and TIMEPART( )

This has been demonstrated below;

SAS DATEPART( ) and TIMEPART( ) Functions

SYNTAX:

DATEPART(sasdate_time_value);

TIMEPART(sasdate_time_value);

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.

Example: SAS DATEPART ( ) and TIMEPART ( ) Functions

SAS Code:

PROC PRINT OUTPUT :

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;

* 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.