SAS | Date 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 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.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    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.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

  • How to read DD-MMM-YY format

    You can use date11. format for both DD-MMM-YY and DD-MMM-YYYY format.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    DATA temp;
        INPUT @6 dt date11.;
        FORMAT dt date11.;
        CARDS;20-jul-19 ;
        PROC PRINT noobs;
    RUN;

    chevron_right

    
    

    Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.