<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SAS Tip: Conversion from Excel Date to SAS Date in SAS Tips from the Community</title>
    <link>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Conversion-from-Excel-Date-to-SAS-Date/m-p/781804#M205</link>
    <description>&lt;P&gt;"Magic numbers" like&amp;nbsp;&lt;SPAN&gt;21916 or&amp;nbsp;20454&amp;nbsp;make code confusing and hard to maintain.&amp;nbsp; And the second one isn't even the right date.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For the default Excel base date of 1900 you want to add the date '30DEC1899'd to the value imported from Excel.&amp;nbsp; Since SAS dates are number of days since 1960 that day in 1899 will be the negative number&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-21,916.&amp;nbsp; The reason to use a date value that is two days before 1900 instead of the first day in 1900 is because of the leap year mistake (or simplification) for the year 1900 used in Excel and because of the different decisions made by SAS and Excel about whether to starting counting days from one or from zero.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For the 1904 base date the 1900 leap year issue will not impact the dates so instead use '31DEC1903'd as the offset. Which is the number -20,455 not -20,454.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note you will only have this issue when SAS decides to import the column with the dates as character strings.&amp;nbsp; So to convert the character variable to a number use the INPUT() function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SAS_date = input(Excel_date,32.) + '30DEC1899'd ;
format SAS_date date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also to get the number of seconds in a day you can just use '24:00't rather than hard coding the number 86,400.&amp;nbsp; Or perhaps just use 24*60*60.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jan 2025 20:30:11 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-01-08T20:30:11Z</dc:date>
    <item>
      <title>SAS Tip: Conversion from Excel Date to SAS Date</title>
      <link>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Conversion-from-Excel-Date-to-SAS-Date/m-p/475824#M177</link>
      <description>&lt;P&gt;Many of us have to convert&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Excel&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;files into&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;SAS&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;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.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;CODE&gt;SAS_date = Excel_date - 21916;&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;SAS_time = Excel_time * 86400;&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;CODE&gt;SAS_date_time = (Excel_date_time - 21916) * 86400;&lt;/CODE&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;NOTE&lt;/STRONG&gt;: 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.&lt;/P&gt;
&lt;P&gt;For additional information on the Excel Date Systems, see MS KB article titled&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="external text" href="http://support.microsoft.com/kb/180162" target="_blank" rel="nofollow"&gt;XL: The 1900 Date System vs. the 1904 Date System&lt;/A&gt;. 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&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="external text" href="http://www.joelonsoftware.com/items/2006/06/16.html" target="_blank" rel="nofollow"&gt;Joel Spolsky&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;This tip was originally published by Pskoo on sasCommunity.org.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 19:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Conversion-from-Excel-Date-to-SAS-Date/m-p/475824#M177</guid>
      <dc:creator>SAS_Tipster</dc:creator>
      <dc:date>2018-07-06T19:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Tip: Conversion from Excel Date to SAS Date</title>
      <link>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Conversion-from-Excel-Date-to-SAS-Date/m-p/781804#M205</link>
      <description>&lt;P&gt;"Magic numbers" like&amp;nbsp;&lt;SPAN&gt;21916 or&amp;nbsp;20454&amp;nbsp;make code confusing and hard to maintain.&amp;nbsp; And the second one isn't even the right date.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For the default Excel base date of 1900 you want to add the date '30DEC1899'd to the value imported from Excel.&amp;nbsp; Since SAS dates are number of days since 1960 that day in 1899 will be the negative number&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-21,916.&amp;nbsp; The reason to use a date value that is two days before 1900 instead of the first day in 1900 is because of the leap year mistake (or simplification) for the year 1900 used in Excel and because of the different decisions made by SAS and Excel about whether to starting counting days from one or from zero.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For the 1904 base date the 1900 leap year issue will not impact the dates so instead use '31DEC1903'd as the offset. Which is the number -20,455 not -20,454.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note you will only have this issue when SAS decides to import the column with the dates as character strings.&amp;nbsp; So to convert the character variable to a number use the INPUT() function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SAS_date = input(Excel_date,32.) + '30DEC1899'd ;
format SAS_date date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also to get the number of seconds in a day you can just use '24:00't rather than hard coding the number 86,400.&amp;nbsp; Or perhaps just use 24*60*60.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2025 20:30:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Conversion-from-Excel-Date-to-SAS-Date/m-p/781804#M205</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-08T20:30:11Z</dc:date>
    </item>
  </channel>
</rss>

