SAS Tip: Conversion from Excel Date to SAS Date (Daily tip for 2026-May-31)
Many of us have to convert Excel files into SAS datasets. Converting date/time value from Excel to SAS can be a hassle as both Excel and SAS have different reference dates (i.e. Day 0 in SAS is 1 January 1960 and Day 0 in Excel is 1 January 1900), below formulas offer great help in terms of converting date/time values from Excel to SAS.
SAS_date = Excel_date - 21916;SAS_time = Excel_time * 86400;SAS_date_time = (Excel_date_time - 21916) * 86400;NOTE: Excel has two different datetime "systems" and the default differs depending on the platform. The above formulas assume Excel is using the 1900 date system. If Excel is using the 1904 Date System, use 20454 in the above formulas instead of 21916.
For additional information on the Excel Date Systems, see MS KB article titled XL: The 1900 Date System vs. the 1904 Date System. The 1900 Date system has other well-known quarks, too. For the background of this dual system in the context of a developer's rather funny/scary encounter with Bill Gates, read this blog entry by Joel Spolsky
This tip was originally published by Pskoo on sasCommunity.org.
Effective Methods for Working With SAS Date Values
Join us to explore how to build and extract date information, plus advanced techniques for generating dynamic, flexible date values. Register for this free Ask the Expert webinar to learn more.
Premiering May 12, 11 am ET
Register Now