<?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: Help converting string datetime in CSV import in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-converting-string-datetime-in-CSV-import/m-p/867974#M342815</link>
    <description>The first appears to have worked.  I will compare to the original data to make sure.</description>
    <pubDate>Tue, 04 Apr 2023 12:40:05 GMT</pubDate>
    <dc:creator>RandoDando</dc:creator>
    <dc:date>2023-04-04T12:40:05Z</dc:date>
    <item>
      <title>Help converting string datetime in CSV import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-converting-string-datetime-in-CSV-import/m-p/867969#M342812</link>
      <description>&lt;P&gt;I have a CSV file that I am importing, and would prefer to have the import statement saved so that it can run regularly to import updates to the CSV file.&amp;nbsp; The file has a date variable stored as text in the format dd/mm/yyyy hh:mm (using 24 hr time).&amp;nbsp; I would prefer to see the imported date as DDMMYYYY HH:MM AM/PM.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am importing on a data step using the infile statement.&amp;nbsp; Here is the gist of what I am running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get a blank column for date with the error: "Invalid argument to function INPUT".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Want;
infile "C:\My File.csv";
length code $12 date $19
input code $ date $ ;
date1 = input(date, Datetime19.);
drop date;
rename date1 = date;
run;
:&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 12:24:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-converting-string-datetime-in-CSV-import/m-p/867969#M342812</guid>
      <dc:creator>RandoDando</dc:creator>
      <dc:date>2023-04-04T12:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: Help converting string datetime in CSV import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-converting-string-datetime-in-CSV-import/m-p/867972#M342813</link>
      <description>&lt;P&gt;Informat DATETIME19. doesn't work because the value is not in the appropriate format. From the &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/leforinforref/p0py1o500c7qsen1hnn2crgejaig.htm" target="_self"&gt;documentation&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The datetime values must be in the following form:&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;ddmmmyy&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;or&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;ddmmmyyyy&lt;/EM&gt;&lt;SPAN&gt;, followed by a blank or special character, followed by&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;hh:mm:ss.ss&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;(the time).&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You don't have that. I leave it as a homework assignment for you to understand what parts of your text string&amp;nbsp;dd/mm/yyyy hh:mm do not match.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This does work:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    datetimestring='19/02/2023 13:22';
run;
data want;
    set have;
    date1=input(datetimestring,anydtdtm.);
    format date1 datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: some people do not like the ANYDTDTM. informat because it is a guessing format, and it could guess wrong. If that's a concern, then this will work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    date1=input(scan(datetimestring,1,' '),ddmmyy10.);
    time1=input(scan(datetimestring,2,' '),time5.);
    date=dhms(date1,hour(time1),minute(time1),0);
    format date datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Apr 2023 12:30:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-converting-string-datetime-in-CSV-import/m-p/867972#M342813</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-04T12:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: Help converting string datetime in CSV import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-converting-string-datetime-in-CSV-import/m-p/867973#M342814</link>
      <description>&lt;P&gt;Maybe like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Want;
infile cards dlm="|";
input code : $ 12. date ANYDTTME.;
format date DATEAMPM23.;
cards;
abc|01/02/2003 04:05
;
run;
proc print data=Want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 12:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-converting-string-datetime-in-CSV-import/m-p/867973#M342814</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-04-04T12:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Help converting string datetime in CSV import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-converting-string-datetime-in-CSV-import/m-p/867974#M342815</link>
      <description>The first appears to have worked.  I will compare to the original data to make sure.</description>
      <pubDate>Tue, 04 Apr 2023 12:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-converting-string-datetime-in-CSV-import/m-p/867974#M342815</guid>
      <dc:creator>RandoDando</dc:creator>
      <dc:date>2023-04-04T12:40:05Z</dc:date>
    </item>
  </channel>
</rss>

