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...
Handling Date Values [3-7]


Additional Date Informats
In the previous section, we saw an example of how to use the (date9.) informat to read data into SAS.

In fact, there are a number of date informats in SAS that allow you to read different types of date values into the data set.

Below are some examples:
Picture

Let's look at an example:
data datelist;
input date : mmddyy10.
      time : time5.

      ;
format date mmddyy10. 
       time time5.;

datalines;
07-14-1983 5:00
05-21-1986 9:00

;
run;

The data step in this example reads a date column and a time column into a data set.

The date values are formatted as 'MM-DD-YYYY' and the time values are formatted as 'HH:MM'.
Picture

These values can be read into a SAS data set using the (mmddyy10.) and (time5.) informats.
Picture

The date and time values are read into the data set and are displayed properly as readable date and time values:
Picture


Additional Date Formats

There are also other date formats available that allow you to display the date values differently.

Below are some examples:
Picture

Let's look at the data step below:
data dateformats;
input date1 : mmddyy10.
      date2 : mmddyy10.
      ;
format date1 weekdate.
       date2 worddate.;

datalines;
07-14-1983 07-14-1983
05-21-1986 05-21-1986
;
run;

The FORMAT statement assigns the (weekdate.) and (worddate.) format to the DATE1 and DATE2 variables, respectively.
Picture

The two date columns are now formatted accordingly.
Picture

Exercise

The code below reads the student ID into SAS along with the student's date of graduation ceremony.

Assign an appropriate informat to format the variables so that the values are read into SAS properly.

The date of graduation ceremony should be displayed in the format of '​Sunday, May 19, 2019'. 
data ceremony;
input studentID ceremonydate;
datalines;
STU1001 19-05-2019
STU1002 20-05-2019
STU1003 21-05-2019
STU1004 22-05-2019
;
run;
Next

Need some help? 


HINT:
The (weekdate.) informat can be used to display the date in the format of 'Sunday, May 19, 2019'.


SOLUTION:

data ceremony;
input studentID $ ceremonydate : ddmmyy10.;
format ceremonydate weekdate.;
datalines;
STU1001 19-05-2019
STU1002 20-05-2019
STU1003 21-05-2019
STU1004 22-05-2019
;
run;


Fill out my online form.
Already a member? Go to member's area.