<?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: convert this datetime string, 9/10/2023 10:00:18 AM,  into date variable, format dd/mm/yyyy in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-this-datetime-string-9-10-2023-10-00-18-AM-into-date/m-p/897150#M354525</link>
    <description>&lt;P&gt;serves me right for not re-reading my question - easy typo to make, albeit a crucial one.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;yeah, that worked. - cheers.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Oct 2023 13:41:53 GMT</pubDate>
    <dc:creator>94seanhogan</dc:creator>
    <dc:date>2023-10-04T13:41:53Z</dc:date>
    <item>
      <title>convert this datetime string, 9/10/2023 10:00:18 AM,  into date variable, format dd/mm/yyyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-this-datetime-string-9-10-2023-10-00-18-AM-into-date/m-p/897128#M354517</link>
      <description>&lt;P&gt;How can I convert a datetime string in the format dd/mm/yyyy hh:mm:ss AM into a date variable in the format yyyy-mm-dd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently doing this:&lt;/P&gt;&lt;P&gt;want = datepart(input(have,anydtdtm.));&lt;/P&gt;&lt;P&gt;format want E8601DA10.;&lt;/P&gt;&lt;P&gt;but its coming out in the American format of yyyy-dd-mm for certain dates such as for&amp;nbsp;9/10/2023 10:00:18 AM is being converted to 2023-10-09, where as I want 2023-09-10.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Oddly enough though, it converts some dates correctly such as&amp;nbsp;9/4/2023 7:00:01 AM which converts to 2023-04-09.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway to make this consistently output the British format of yyyy-mm-dd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cheers.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 11:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-this-datetime-string-9-10-2023-10-00-18-AM-into-date/m-p/897128#M354517</guid>
      <dc:creator>94seanhogan</dc:creator>
      <dc:date>2023-10-04T11:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: convert this datetime string, 9/10/2023 10:00:18 AM,  into date variable, format dd/mm/yyyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-this-datetime-string-9-10-2023-10-00-18-AM-into-date/m-p/897135#M354519</link>
      <description>&lt;P&gt;It sounds like you source datetime have different formats?&lt;/P&gt;
&lt;P&gt;Using anydtxxxx formats should be the "last" resort, since mapping can happen randomly.&lt;/P&gt;
&lt;P&gt;Analyze your data, and potentially use different informats based on some logic.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 12:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-this-datetime-string-9-10-2023-10-00-18-AM-into-date/m-p/897135#M354519</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2023-10-04T12:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: convert this datetime string, 9/10/2023 10:00:18 AM,  into date variable, format dd/mm/yyyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-this-datetime-string-9-10-2023-10-00-18-AM-into-date/m-p/897148#M354523</link>
      <description>&lt;P&gt;Please think about what you say. You say you have data in dd/mm/yyyy hh:mm:ss&amp;nbsp; layout. So the first value is the day.&lt;/P&gt;
&lt;P&gt;Then complain when 9/10/2023 10:00:18 AM is being converted to 2023-10-09. 09 is the DAY. so if you want YYYY-DD-MM then do not use E8601DA format,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;H1 id="n1xn1ozuh3bpo6n180mtyrnssslh" class="xis-title"&gt;&lt;A name="~1" target="_blank"&gt;&lt;/A&gt;&lt;FONT style="background-color: #fcdec0;"&gt;E8601DA&lt;/FONT&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;w.&lt;/SPAN&gt; Format&lt;/H1&gt;
&lt;P class="xis-shortDescription"&gt;Writes date values by using the ISO 8601 extended notation &lt;SPAN class="xis-userSuppliedValue"&gt;yyyy-mm-dd&lt;/SPAN&gt;.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I cannot replicate this: Oddly enough though, it converts some dates correctly such as 9/4/2023 7:00:01 AM which converts to 2023-04-09.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ANYDTDTE and other "any date" functions are guessing. Do not allow that. Use something where YOU control the informat. If that initial value is indeed in ddmmyy structure then:&lt;/P&gt;
&lt;PRE&gt;data example;
   x="9/10/2023 10:00:18 AM";
   date = input(scan(x,1,' '),ddmmyy10.);
   format date yymmdd10.;
run;&lt;/PRE&gt;
&lt;P&gt;The above extracts the date part and controls which informat is used to read the date portion.&lt;/P&gt;
&lt;P&gt;If you want to display the value in yy/dd/mm order then you must create a custom format to do so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 13:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-this-datetime-string-9-10-2023-10-00-18-AM-into-date/m-p/897148#M354523</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-10-04T13:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: convert this datetime string, 9/10/2023 10:00:18 AM,  into date variable, format dd/mm/yyyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-this-datetime-string-9-10-2023-10-00-18-AM-into-date/m-p/897150#M354525</link>
      <description>&lt;P&gt;serves me right for not re-reading my question - easy typo to make, albeit a crucial one.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;yeah, that worked. - cheers.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 13:41:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-this-datetime-string-9-10-2023-10-00-18-AM-into-date/m-p/897150#M354525</guid>
      <dc:creator>94seanhogan</dc:creator>
      <dc:date>2023-10-04T13:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: convert this datetime string, 9/10/2023 10:00:18 AM,  into date variable, format dd/mm/yyyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-this-datetime-string-9-10-2023-10-00-18-AM-into-date/m-p/897155#M354528</link>
      <description>&lt;P&gt;People do display date strings in DMY and MDY order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To avoid that confusion you should display dates in YMD order since NOBODY displays dates in YDM order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case just use DDMMYY informat to convert the date part of your string into a date value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you did need to use one of the ANYDT... informats then make sure to set the DATESTYLE system option to let it know what informat to use for values where the day of the month is less than 13.&amp;nbsp; So if you want ANYDT.. informats to treat 9/10/2023 as the Ninth of October instead of September Tenth then set DATESTYLE=DMY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 13:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-this-datetime-string-9-10-2023-10-00-18-AM-into-date/m-p/897155#M354528</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-04T13:55:53Z</dc:date>
    </item>
  </channel>
</rss>

