Extract hours, minutes and seconds from timestamp in SAS

Extract hours, minutes and seconds from timestamp in SAS is accomplished using hour(), minute() and second() respectively.  Extract hour from timestamp in SAS is done using hour(). Extract minute from timestamp in SAS is done using minute().Extract seconds from timestamp in SAS is done using second(). Let’s see an example of each.

  • Extract hour from timestamp in SAS is done using hour() Function
  • Extract minutes from timestamp in SAS is done using minute() Function
  • Extract seconds from timestamp in SAS is done using second() Function

So we will be using EMP_DET Table in our example

Extract hours, minutes and seconds from timestamp in SAS 1

 

Extract Hour from timestamp in SAS:

Extracting Hour from timestamp in SAS is accomplished using hour() function. In the below example we have extracted hour of the last_login.


data emp_det1; 
set emp_det; 
hour_part = hour(last_login); 
run;

So the resultant table with hour extracted from datetime will be

Extract hours, minutes and seconds from timestamp in SAS 2

 

 

Extract Minutes from timestamp in SAS:

Extracting minutes from timestamp in SAS is accomplished using minute() function. In the below example we have extracted minute of the last_login.


/* extract minute */ 

data emp_det1; 
set emp_det; 
minute_part = minute(last_login); 
run; 

So the resultant table with minutes extracted from datetime will be

Extract hours, minutes and seconds from timestamp in SAS 3

 

 

Extract Seconds from timestamp in SAS:

Extracting Seconds from timestamp in SAS is accomplished using second() function. In the below example we have extracted second of the last_login.


/* extract second */ 

data emp_det1; 
set emp_det; 
second_part = second(last_login); 
run;

So the resultant table with second extracted from datetime will be

Extract hours, minutes and seconds from timestamp in SAS 4