Search the site...

SASCRUNCH TRAINING
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
Sentry Page Protection
Please Wait...
Variable Attributes [12-17]


Date & Time Format
In the last session, we introduce you the (YYMMDD10.) format. 

In fact, there are some other date formats that are commonly used in SAS:

  • YYMMDD10.
  • Date9.
  • Date7.
  • MMDDYY10.

Example
Picture

The DFMT data set above contains Date1, Date2, Date3 and Date4. 

Each date contains an identical set of data.

Now, I'm going to assign the following formats to each of the date variables:

  • Date1: YYMMDD10.
  • Date2: Date9.
  • Date3: Date7.
  • Date4: MMDDYY10.

Example

Data DFmt2;
Set DFmt;
Format Date1 YYMMDD10.
       Date2 Date9.
       Date3 Date7.
       Date4 MMDDYY10.;
Run;
Picture

(YYMMDD10.) = 1992-11-09
(Date9.)    = 09NOV1992
(Date7.)    = 09NOV92
(MMDDYY10.) = 11/09/1992


Time Format

The two common time formats are:
  • Time5. (00:00)
  • Time8. (00:00:00)

Example
Picture

In the TFMT data set, the two time variables contain a set of identical time values.

Now, let's apply the two time formats to Time1 and Time2. 

Example

Data TFmt2;
Set TFmt;
Format Time1 Time5.
       Time2 Time8.;

Run;
Picture

Exercise

Copy and run the code from the yellow box below:
Picture

The ATTENDANCE data set contains 4 variables:
  • EmpID: Employee ID
  • Date: Date of Attendance
  • In: Time arriving the office
  • Out: Time departing the office


The date and time variables are not formatted properly.

Tasks
1. Format the Date and Time variables with the proper formats. 
2. An employee is considered late if they arrive after 9 a.m. Find out which employee is late.
Next

Need some help? 


HINT:
9 am = 9 hours after mid-night = 32400 seconds after mid-night.


SOLUTION:
Data Attendance2;
Set Attendance;
Format Date yymmdd10. In Out Time8.;

If In>32400 then Late = "Yes";
Run;


Fill out my online form.

Already a member? Go to member's area.