Open In App

SAS | Date Formats and Informats

Last Updated : 30 Jul, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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 in sample data which is being created using CARDS/DATALINES statement or read or import data from either an external file (Text/Excel/CSV).

Formats can be used in both Data Steps and PROC Steps whereas Informat can be used only in Data Steps.

Example: Read Dates in SAS

  • In the example 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.;
        CARDS;20-07-19 20-07-2019 ;
    RUN;

    
    

    The INFORMATS ddmmyy8. is used to read 20-07-19 date and ddmmyy10. to read 20-07-2019 date. In defined syntax above, 8 and 10 refers to width of the date.

    The created dataset looks like below –

    It returns 21750 as it is in the SAS date value form. It is not meaningful if you look at the value. You cannot tell which date it is.

  • To display the date in usual date format, use FORMAT statement.




    DATA sampledata;
        INPUT @6 date1 ddmmyy8. @15 date2 ddmmyy10.;
        FORMAT date1 ddmmyy8. date2 ddmmyy10.;
        CARDS;20-07-19 20-07-2019 ;
    RUN;

    
    

    Output:

  • 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.;
        CARDS;20-jul-19 ;
        PROC PRINT noobs;
    RUN;

    
    

    Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads