<?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 Import csv file with datetime variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527245#M143701</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to import a csv file containing a datetime filled this way:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;01/06/2018 21:45&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where 01 is the day, then 06 the month, 2018 the year, 21 the hour and 45 the minute.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, by default SAS is using the ANYDTDTM16. informat which seems to be the US informat with the month filled before the day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To do so, I used the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;CODE class=" language-sas"&gt;PROC IMPORT DATAFILE="&amp;amp;Folder./&amp;amp;File" OUT=TempRH DBMS=CSV REPLACE;

DELIMITER=";";

INFORMAT Date_Heure datetime20.;

RUN;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Does anyone know how to import this correctly?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Thank you.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Cédric&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Jan 2019 09:15:17 GMT</pubDate>
    <dc:creator>CedricLVQ</dc:creator>
    <dc:date>2019-01-15T09:15:17Z</dc:date>
    <item>
      <title>Import csv file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527245#M143701</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to import a csv file containing a datetime filled this way:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;01/06/2018 21:45&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where 01 is the day, then 06 the month, 2018 the year, 21 the hour and 45 the minute.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, by default SAS is using the ANYDTDTM16. informat which seems to be the US informat with the month filled before the day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To do so, I used the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;CODE class=" language-sas"&gt;PROC IMPORT DATAFILE="&amp;amp;Folder./&amp;amp;File" OUT=TempRH DBMS=CSV REPLACE;

DELIMITER=";";

INFORMAT Date_Heure datetime20.;

RUN;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Does anyone know how to import this correctly?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Thank you.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Cédric&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 09:15:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527245#M143701</guid>
      <dc:creator>CedricLVQ</dc:creator>
      <dc:date>2019-01-15T09:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527251#M143706</link>
      <description>&lt;P&gt;Does this generate an error? If yes, post the log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also import a csv file with the INFILE Statement in a data step. Tons of examples in here.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 09:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527251#M143706</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-15T09:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527254#M143708</link>
      <description>&lt;P&gt;ANYDTDTM also works with datetime values with day first&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 10:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527254#M143708</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2019-01-15T10:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527262#M143710</link>
      <description>&lt;P&gt;First of all, &lt;EM&gt;you&lt;/EM&gt; are more intelligent than a few grams of silicone, so it's time for you to take over.&lt;/P&gt;
&lt;P&gt;Take the data step code created and run by proc import from the log, and adapt it. Read the datetime value into a string, dissect it into its two parts with scan(), input the first part with ddmmyy10., the second with time8., and then build your datetime value with the dhms() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want = dhms(input(scan(string,1),ddmmyy10.),0,0,input(scan(string,2),time5.));
format want e8601dt19.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Jan 2019 10:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527262#M143710</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-15T10:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527275#M143713</link>
      <description>Try add an option.

options datestyle=dmy;</description>
      <pubDate>Tue, 15 Jan 2019 12:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527275#M143713</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-01-15T12:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527277#M143715</link>
      <description>&lt;P&gt;No error in the log, not even a warning but the import date time is 06JAN2018 21:45 instead of 01JUN2018 21:45&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 12:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527277#M143715</guid>
      <dc:creator>CedricLVQ</dc:creator>
      <dc:date>2019-01-15T12:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527278#M143716</link>
      <description>&lt;P&gt;Try add an option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options datestyle=dmy;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 12:54:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527278#M143716</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-01-15T12:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527279#M143717</link>
      <description>&lt;P&gt;Wouah, thanks, that works great!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 12:55:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527279#M143717</guid>
      <dc:creator>CedricLVQ</dc:creator>
      <dc:date>2019-01-15T12:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv file with datetime variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527280#M143718</link>
      <description>&lt;P&gt;Thank you for you help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My colleague advised me to use this trick but it seems that adding:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options datastyle=dmy works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 12:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-file-with-datetime-variable/m-p/527280#M143718</guid>
      <dc:creator>CedricLVQ</dc:creator>
      <dc:date>2019-01-15T12:57:07Z</dc:date>
    </item>
  </channel>
</rss>

