The APP_DT is the date the application was submitted.
The DEADLINE_DT is the application deadline.
Both are created using the datetime constant:
The variables are assigned the (datetime.) format as well:
The full datetime values are displayed for both variables:
Comparing Datetime Variables
Similar to the date and time variables, we can compare two datetime variables to get the correct sequence of the events.
Example
data example;
format app_dt deadline_dt datetime.; app_dt = '05MAY2019/18:30:07'dt; deadline_dt = '01MAY2019/12:30:00'dt;
if app_dt > deadline_dt then Late_flag = "Y"; else Late_flag = "N";
run;
In this example, we checked whether the application was submitted after the deadline and created a LATE_FLAG variable that indicates whether the application was submitted late.
It turns out that the application was indeed submitted late:
DATEPART and TIMEPART Functions
The DATEPART and TIMEPART functions allow you to extract the date and time value from a datetime variable.
Let's look at an example.
data example;
format app_dt datetime.; app_dt = '05MAY2019/18:30:07'dt;
format date date9. time time8.;
date = datepart(app_dt); time = timepart(app_dt);
run;
The DATE and TIME variables are created using the DATEPART and TIMEPART functions, respectively, on the APP_DT variable:
The date and time of the application date are extracted into the DATE and TIME variables:
DHMS Function
The DHMS function allows you to combine the date, hours, minutes and seconds into a datetime variable.
Let's look at an example.
data example2;
format date date9.; date = '15AUG2018'd; hour = 8; minute = 30; second = 45;
format datetime datetime.; datetime = dhms(date, hour, minute, second);
run;
In this example, the DATE, HOUR, MINUTE and SECOND columns are created and they are used in the parameters of the DHMS function:
The DATETIME variable is created based on the data from the DATE, HOUR, MINUTE and SECOND variables:
Common Usage of the DHMS Function
The DHMS function is commonly used to combine the date and time variables.