<?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 CSV file, datetime conversion problem in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/CSV-file-datetime-conversion-problem/m-p/56898#M15915</link>
    <description>Hi Learned SAS Users,&lt;BR /&gt;
    I've researched this with no success.  I have VERY large CSV files containing datetime variables (with lots of other data), and I can read these successfully using the IMPORT wizard successfully IF I convert the data to MS 2003 Excel files.  However, I have had no luck converting the datatime values just reading them in with the IMPORT wizard as CSV, or trying  my hand with inputs (and informats)&lt;BR /&gt;
&lt;BR /&gt;
A typical data line looks like:&lt;BR /&gt;
3,2008-04-22 12:10:00.0,1504.127,2352.149,15.703,15.451&lt;BR /&gt;
&lt;BR /&gt;
where the second data value is a datetime string.&lt;BR /&gt;
&lt;BR /&gt;
The error I get is 'invalid data for' time (second variable).&lt;BR /&gt;
&lt;BR /&gt;
Any suggestions?</description>
    <pubDate>Fri, 24 Oct 2008 19:29:46 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-10-24T19:29:46Z</dc:date>
    <item>
      <title>CSV file, datetime conversion problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/CSV-file-datetime-conversion-problem/m-p/56898#M15915</link>
      <description>Hi Learned SAS Users,&lt;BR /&gt;
    I've researched this with no success.  I have VERY large CSV files containing datetime variables (with lots of other data), and I can read these successfully using the IMPORT wizard successfully IF I convert the data to MS 2003 Excel files.  However, I have had no luck converting the datatime values just reading them in with the IMPORT wizard as CSV, or trying  my hand with inputs (and informats)&lt;BR /&gt;
&lt;BR /&gt;
A typical data line looks like:&lt;BR /&gt;
3,2008-04-22 12:10:00.0,1504.127,2352.149,15.703,15.451&lt;BR /&gt;
&lt;BR /&gt;
where the second data value is a datetime string.&lt;BR /&gt;
&lt;BR /&gt;
The error I get is 'invalid data for' time (second variable).&lt;BR /&gt;
&lt;BR /&gt;
Any suggestions?</description>
      <pubDate>Fri, 24 Oct 2008 19:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/CSV-file-datetime-conversion-problem/m-p/56898#M15915</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-24T19:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: CSV file, datetime conversion problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/CSV-file-datetime-conversion-problem/m-p/56899#M15916</link>
      <description>Hi:&lt;BR /&gt;
  The data step INFILE and INPUT should work for you. There are some "ANY" informats that you should be able to find in the INFORMAT list. The ANYDTDTE informat extracts the date part from the derived value. The ANYDTDTM informat extracts the datetime part. The ANYDTTME informat extracts the time part. If you read with ANYDTDTM, for example, to get the complete datetime value, then you can use the DATEPART and TIMEPART functions to create new variables for just date and/or just time if you need to.&lt;BR /&gt;
&lt;BR /&gt;
The way you read with a special informat is to use the colon modifier to tell SAS which informat to use -- other than the standard numeric informat. (For your value, as shown in your posting, the standard DATETIME informat won't work because your date is not in the "standard" form of &lt;B&gt;&lt;BR /&gt;
ddmmmyy hh:mm:ss.ss &lt;/B&gt;.) But the "ANY" informat should work (statement below assumes all vars are numeric):&lt;BR /&gt;
[pre]&lt;BR /&gt;
              &lt;BR /&gt;
  infile 'c:\temp\myfile.csv' dsd dlm=',';&lt;BR /&gt;
  input id date_time : anydtdtm21. var1 var2 var3 var4;&lt;BR /&gt;
  dateonly = datepart(date_time);&lt;BR /&gt;
  timeonly = timepart(date_time);&lt;BR /&gt;
           &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Sat, 25 Oct 2008 13:06:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/CSV-file-datetime-conversion-problem/m-p/56899#M15916</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-10-25T13:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: CSV file, datetime conversion problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/CSV-file-datetime-conversion-problem/m-p/56900#M15917</link>
      <description>Thanks for the tip...works great!&lt;BR /&gt;
&lt;BR /&gt;
Here's how I used that informat:&lt;BR /&gt;
&lt;BR /&gt;
 infile 'C:\perry\carbonscience\SasProgs\sens7_8-10.csv' delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;&lt;BR /&gt;
        informat logger_id best32. ;&lt;BR /&gt;
        informat date_time anydtdtm21. ;&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
        format logger_id best12. ;&lt;BR /&gt;
        format date_time anydtdtm21. ;&lt;BR /&gt;
&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
&lt;BR /&gt;
        input&lt;BR /&gt;
                 logger_id&lt;BR /&gt;
                 date_time&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.</description>
      <pubDate>Tue, 28 Oct 2008 03:03:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/CSV-file-datetime-conversion-problem/m-p/56900#M15917</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-28T03:03:21Z</dc:date>
    </item>
  </channel>
</rss>

