<?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: How to read a date value from excel to SAS? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-a-date-value-from-excel-to-SAS/m-p/772482#M245284</link>
    <description>&lt;P&gt;The digit string is the number that Excel uses for the date.&lt;/P&gt;
&lt;P&gt;The default in Excel is to use 1900 as the starting point for numbering days.&amp;nbsp; To convert it add the date '30DEC1899'd to the value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datevar = input(charvar,32.) + '30DEC1899'd ;
format datevar date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that Excel can also use 1904 as the base date.&amp;nbsp; If that is happening you probable will want to use '31DEC1903'd as the offset to add. The one day difference is because Excel treats 1900 as a leap year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your example date of 22MAY2021 will be the number 44,338 in Excel.&lt;/P&gt;
&lt;PRE&gt;586   data test;
587     datevar='22may2021'd;
588     charvar=put(datevar-'30dec1899'd,10.-L);
589     format datevar date9.;
590     put (_all_) (=);
591   run;

datevar=22MAY2021 charvar=44338
&lt;/PRE&gt;</description>
    <pubDate>Wed, 06 Oct 2021 16:44:54 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-10-06T16:44:54Z</dc:date>
    <item>
      <title>How to read a date value from excel to SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-a-date-value-from-excel-to-SAS/m-p/772471#M245281</link>
      <description>&lt;P&gt;Hi, I am having this weird issue when importing data from excel to SAS. One of the columns in the excel is a date value. (Ex: 05/22/2012). However, in this column, there is also N/A which indicates that there is no date value available for this row. When I import the table from excel to SAS, it stored this column as a character value because of the N/A, I totally understand. But it also automatically changed 05/22/2012 to digits like 354562 and stored it as a character. I thought this number is the numeric format for that date. But when I change the number format back to the date format, it is showing me a completely different date like 05/21/2064. Does anyone know why it is happening and how to solve this problem?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 16:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-a-date-value-from-excel-to-SAS/m-p/772471#M245281</guid>
      <dc:creator>JQian</dc:creator>
      <dc:date>2021-10-06T16:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to read a date value from excel to SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-a-date-value-from-excel-to-SAS/m-p/772482#M245284</link>
      <description>&lt;P&gt;The digit string is the number that Excel uses for the date.&lt;/P&gt;
&lt;P&gt;The default in Excel is to use 1900 as the starting point for numbering days.&amp;nbsp; To convert it add the date '30DEC1899'd to the value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datevar = input(charvar,32.) + '30DEC1899'd ;
format datevar date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that Excel can also use 1904 as the base date.&amp;nbsp; If that is happening you probable will want to use '31DEC1903'd as the offset to add. The one day difference is because Excel treats 1900 as a leap year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your example date of 22MAY2021 will be the number 44,338 in Excel.&lt;/P&gt;
&lt;PRE&gt;586   data test;
587     datevar='22may2021'd;
588     charvar=put(datevar-'30dec1899'd,10.-L);
589     format datevar date9.;
590     put (_all_) (=);
591   run;

datevar=22MAY2021 charvar=44338
&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Oct 2021 16:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-a-date-value-from-excel-to-SAS/m-p/772482#M245284</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-06T16:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to read a date value from excel to SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-a-date-value-from-excel-to-SAS/m-p/772484#M245286</link>
      <description>Worked perfectly. Thanks!</description>
      <pubDate>Wed, 06 Oct 2021 16:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-a-date-value-from-excel-to-SAS/m-p/772484#M245286</guid>
      <dc:creator>JQian</dc:creator>
      <dc:date>2021-10-06T16:47:19Z</dc:date>
    </item>
  </channel>
</rss>

