<?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: import date data from excel in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/import-date-data-from-excel/m-p/392723#M94534</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Please provide your code and ideally also attach a sample Excel file which illustrates the issue when using your code.&lt;/P&gt;</description>
    <pubDate>Sat, 02 Sep 2017 10:22:12 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-09-02T10:22:12Z</dc:date>
    <item>
      <title>import date data from excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-date-data-from-excel/m-p/392721#M94533</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I am using data step to import data from excel.&lt;/P&gt;&lt;P&gt;I have 1 column with date values that are displayed in excel with "Number " format.&lt;/P&gt;&lt;P&gt;(For example : in excel value 42980 represnt &amp;nbsp;02SEP2017&lt;/P&gt;&lt;P&gt;In sas data step i define the date varaible as a numeric and give a format ddmmyy10.&lt;/P&gt;&lt;P&gt;The problem is that the date appears in SAS is not&amp;nbsp;&lt;SPAN&gt;02SEP2017!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I found a solution to change the format in excel to 3/14/2001 (means &amp;nbsp;mm/dd/yyyy).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The problem is that my client doesn't want to change the format in excel.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Can you offer me a solution ?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Sep 2017 09:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-date-data-from-excel/m-p/392721#M94533</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2017-09-02T09:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: import date data from excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-date-data-from-excel/m-p/392723#M94534</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Please provide your code and ideally also attach a sample Excel file which illustrates the issue when using your code.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Sep 2017 10:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-date-data-from-excel/m-p/392723#M94534</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-02T10:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: import date data from excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-date-data-from-excel/m-p/392748#M94546</link>
      <description>&lt;P&gt;Normally SAS will automatically adjust the dates for you. &amp;nbsp;Where I have seen it fail is when you have dates and character strings in the same column so that SAS imports the field as character instead of numeric. When that happens it pulls over the internal number that Excel uses for the data as a string of digits. &amp;nbsp;I have never seen it do that and put the number into a numeric field instead, but perhaps you had a column with mixed dates and other numbers so that SAS decided the column was numeric, but did not think it was a date?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You just need to adjust the offset. &amp;nbsp;SAS uses 01JAN1960 and Excel uses 01JAN1900. &amp;nbsp;Then -2 in the formula is because SAS starts from zero and Excel starts from one and Excel mistakenly thinks that 1900 was a leap year. (So if you have dates that are before 01MAR1900 the result will be off by one).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test ;
  mydate=42980;
  shouldbe='02SEP2017'd;
  put 'BEFORE: ' mydate= comma7. +1 mydate date9. +1 shouldbe= date9. ;
  mydate = mydate + '01JAN1900'd -2 ;
  put 'AFTER : ' mydate= comma7. +1 mydate date9. +1 shouldbe= date9. ;
  format mydate shouldbe date9. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;2115  data test ;
2116    mydate=42980;
2117    shouldbe='02SEP2017'd;
2118    put 'BEFORE: ' mydate= comma7. +1 mydate date9. +1 shouldbe= date9. ;
2119    mydate = mydate + '01JAN1900'd -2 ;
2120    put 'AFTER : ' mydate= comma7. +1 mydate date9. +1 shouldbe= date9. ;
2121    format mydate shouldbe date9. ;
2122  run;

BEFORE: mydate=42,980  03SEP2077 shouldbe=02SEP2017
AFTER : mydate=21,064  02SEP2017 shouldbe=02SEP2017
NOTE: The data set WORK.TEST has 1 observations and 2 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Sep 2017 14:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-date-data-from-excel/m-p/392748#M94546</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-02T14:27:47Z</dc:date>
    </item>
  </channel>
</rss>

