SAS Date Formats and Informats

This tutorial describes the usage of SAS Date formats and informats. It includes practical real-world data problems related to SAS formats.

What are Formats and Informats?

Informats is used to tell SAS how to read a variable whereas Formats is used to tell SAS how to display or write values of a variable.

Informats is basically used when you read or import data from either an external file (Text/Excel/CSV) or read in sample data which was created using CARDS/DATALINES statement. It is also used when you create a new variable in a dataset.

Formats can be used in both Data Steps and PROC Steps whereas Informat can be used only in Data Steps. Let's understand by examples -

Example 1 - Read Dates in SAS

In the program below, we have used INFORMATS ddmmyy8. and ddymmyy10. to read dates in SAS. It creates a dataset called sampledata which is stored in WORK library.

DATA sampledata;
     INPUT @6 date1 ddmmyy8. @15 date2 ddmmyy10.;
     30-12-16 30-12-2016
The INFORMATS ddmmyy8. is used to read 30-12-16 date and ddmmyy10. to read 30-12-2016 date. In this case, 8 and 10 refers to width of the date.

The created dataset looks like below -
Read SAS Date
It returns 20818 as it is in SAS date value form. It is not meaningful if you look at the value. You cannot tell which date it is. To display in real date form, use FORMAT statement.
DATA sampledata;
     INPUT @6 date1 ddmmyy8. @15 date2 ddmmyy10.;
     FORMAT date1 ddmmyy8. date2 ddmmyy10.;
     30-12-16 30-12-2016
Output : SAS Format

How to read DD-MMM-YY format

You can use date11. format for both DD-MMM-YY and DD-MMM-YYYY format.
DATA temp;
     INPUT @6 dt date11.;
     FORMAT dt date11.;
Result : 10-OCT-2014

Example 2 - Display Today's Date

The today() function can be used to generate current date.
data _null_;
    format dt yymmdd10.;
    put dt ;
Result : It returns 2016-12-30 as 30DEC2016 is the today's date. It's in YYYY-MM-DD format because we've used yymmdd10. format. The 10 refers to the width of the date as 2016-12-30 contains 10 elements. The PUT statement is used to show value in log window.

To display date in WORD format

1. Short Word Date Format

The format date9. returns 30DEC2016.
format dt date9.;

2. Complete Word Date Format

The format WORDDATE. returns DECEMBER 30, 2016. No need to specify width in this format. It automatically adjusts the width depending on the month.
format dt WORDDATE.;

3. Including WEEK

The format WEEKDATE. gives Friday, December 30, 2016
format dt WEEKDATE.;

Display DAY / MONTH / YEAR

In this section, we will see how we can write only day, month, year and weekday.
data _null_;
put "Day :"  dt  DAY.;
put "Month :" dt MONTH.;
put "YEAR:" dt YEAR.;
SAS : Date Formats
We can also use FORMAT in the PUT statement without specifying FORMAT statement explicitly. The DAY. format returned 30, MONTH. format returned 12 and YEAR. format returned 2016. In addition, we have used DOWNAME. format to extract weekday (Friday).

Other Popular Formats

Some of the commonly used date formats are listed below -
Formats Result
DDMMYYP10. 30.12.2016
DDMMYYS10. 30/12/2016
MMDDYYP10. 12.30.2016
MMDDYYS10. 12/30/2016


Hope you have a better understanding of the difference between SAS Date Formats and Informats and how they are used after completing this tutorial.

SAS Tutorials : 100 Free SAS Tutorials

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 7 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like banking, Telecom, HR and Health Insurance.

While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*
Related Posts:
10 Responses to "SAS Date Formats and Informats"
  1. can we use informat and format in excel import ?
    if it is possible can u send me code.

  2. How i can read 10-oct-14 format ?

    1. I have added 'how to read this format' in the post. Hope it helps!

  3. How to use datetime() with format? A small program example will be of great help.

  4. deepanshu I have a querry. when we extract the month from date like 24-08-2017 it guves results as Month =8. What to do if i want to find out the name of that month like output is Month = August

    1. Hi ,

      you can do this by using format varname monname.;

      it will print month name.

    2. Use "monname"

      Example :
      data xyz;
      format dt monname.;

  5. Why used @6 and @15 in the below statment.

    INPUT @6 date1 ddmmyy8. @15 date2 ddmmyy10.;

  6. Hello Deepanshu
    as we have different dates in one format using anydtdte.
    can we convert dates in one variable in different formats?

  7. what is the use of @ in this chapter. i believe this @ symbol is used for the formatting.


Next → ← Prev