<?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 char datetime to sas date format with EU format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/650871#M195205</link>
    <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255991" target="_blank" rel="noopener"&gt;yelkenli&lt;/A&gt;&lt;/P&gt;
&lt;DIV class="sas-author-rank"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;You can use the following approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   mydatetime = '28/02/2020 15:48:20,000'; output;
   mydatetime = '01/03/2020 15:48:20,000'; output;
run;

data want (keep=mydatetime tadt);
   set have;
   datec = substr(mydatetime,1,10);
   timec = substr(mydatetime, 12,8);
   date = input(datec,ddmmyy10.);
   time = input(timec,time8.);
   tadt = dhms(date,hour(time),minute(time),second(time));
   format tadt datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
    <pubDate>Tue, 26 May 2020 18:19:16 GMT</pubDate>
    <dc:creator>LeonidBatkhan</dc:creator>
    <dc:date>2020-05-26T18:19:16Z</dc:date>
    <item>
      <title>Convert char datetime to sas date format with EU format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/650850#M195196</link>
      <description>&lt;P&gt;I see many threads and documentation on this subject, but cannot find the correct input format for my problem.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My date time format in $CHAR23. is&amp;nbsp;&amp;nbsp;'28/02/2020 15:48:20,000'&lt;/P&gt;&lt;P&gt;the ',000' portion is not needed, so I can strip that out --&amp;gt;&amp;nbsp;'28/02/2020 15:48:20'&lt;/P&gt;&lt;P&gt;Can someone point me to the correct method to translate this to a sas date time?&amp;nbsp; the any-datetime method does not work as it gives Jan 3 for 01/03/2020 (should be March 1) and February 28 for 28/02/2020 in the same dataset.&amp;nbsp; otherwise it returns without error.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep=mydatetime datetime tadt);
set have;
datetime=substr(mydatetime,1,19);
tadt=input(datetime, anydtdtm19.);
format tadt datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;i have tried also with&amp;nbsp;MMDDYY19. after stripping out the backslashes.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 17:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/650850#M195196</guid>
      <dc:creator>yelkenli</dc:creator>
      <dc:date>2020-05-26T17:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: Convert char datetime to sas date format with EU format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/650871#M195205</link>
      <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255991" target="_blank" rel="noopener"&gt;yelkenli&lt;/A&gt;&lt;/P&gt;
&lt;DIV class="sas-author-rank"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;You can use the following approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   mydatetime = '28/02/2020 15:48:20,000'; output;
   mydatetime = '01/03/2020 15:48:20,000'; output;
run;

data want (keep=mydatetime tadt);
   set have;
   datec = substr(mydatetime,1,10);
   timec = substr(mydatetime, 12,8);
   date = input(datec,ddmmyy10.);
   time = input(timec,time8.);
   tadt = dhms(date,hour(time),minute(time),second(time));
   format tadt datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 18:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/650871#M195205</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2020-05-26T18:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: Convert char datetime to sas date format with EU format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/650879#M195208</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   mydatetimeStr = '28/02/2020 15:48:20,000'; output;
   mydatetimeStr = '01/03/2020 15:48:20,000'; output;
run;

data want;
set have;
myDate = datepart(input(myDateTimeStr, anydtdtm.));
format myDate yymmdd10.;
run;

proc print data=want noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;mydatetimeStr 	                myDate
28/02/2020 15:48:20,000 	2020-02-28
01/03/2020 15:48:20,000 	2020-03-01&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 May 2020 18:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/650879#M195208</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-05-26T18:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Convert char datetime to sas date format with EU format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/650909#M195220</link>
      <description>I think your main issue has been answered, but have a look at the formats starting with E8601  (Eg.  E8601DN10.) &lt;BR /&gt;Also look into formats NLDATE or YYMMDDP  or YYMMDDN.    &lt;BR /&gt;The datetime19. formats mentioned elsewhere have English month names in them, and after Brexit, only the Irish speak English in the EU &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
      <pubDate>Tue, 26 May 2020 19:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/650909#M195220</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-05-26T19:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert char datetime to sas date format with EU format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651018#M195269</link>
      <description>&lt;P&gt;I don't like the "any" informats, as they will give unpredictable results depending on locale settings. Also see Maxim 31.&lt;/P&gt;
&lt;P&gt;I am rather strict:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   mydatetime = '28/02/2020 15:48:20,000'; output;
   mydatetime = '01/03/2020 15:48:20,123'; output;
run;

data want;
set have;
mydate = input(mydatetime,ddmmyy10.);
mytime = input(scan(mydatetime,2," "),time8.);
mydt = dhms(mydate,0,0,mytime);
format
  mydate yymmddd10.
  mytime time8.
  mydt e8601dt24.3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The longer datetime format is used only to show that the fractional part of the time has been successfully stripped.&lt;/P&gt;
&lt;P&gt;If the original data had the date in YMD order, it could be read directly with the e8601dt informat:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   mydatetime = '2020-02-28 15:48:20,000'; output;
   mydatetime = '2020-03-01 15:48:20,123'; output;
run;

data want;
set have;
mydt = input(mydatetime,e8601dt19.);
format
  mydt e8601dt24.3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 May 2020 09:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651018#M195269</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-27T09:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: Convert char datetime to sas date format with EU format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651055#M195290</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you swap your two outputs and see if you get these results?&amp;nbsp; I think SAS is reading the first line and determining where the month and day are, and applying that format to all rows.&amp;nbsp; This is similar to the risk you get when importing data without controlling the format, SAS will use the first n observations to assign a format&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   mydatetimeStr = '01/03/2020 15:48:20,000'; output;
   mydatetimeStr = '28/02/2020 15:48:20,000'; output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;with your code I get:&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;mydatetimeStr myDate &lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;01/03/2020 15:48:20,000&lt;/TD&gt;&lt;TD&gt;2020-01-03&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;28/02/2020 15:48:20,000&lt;/TD&gt;&lt;TD&gt;2020-02-28&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;When I ran it with my table, I got the year 1960.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV class=" dgrid-row dgrid-row-even ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;01/03/2020 00:00:00,000&lt;/TD&gt;&lt;TD&gt;01JAN60:06&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-odd ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;01/03/2020 00:00:01,000&lt;/TD&gt;&lt;TD&gt;01JAN60:06&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-even ui-state-default dgrid-selected ui-state-active"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;01/03/2020 00:00:02,000&lt;/TD&gt;&lt;TD&gt;01JAN60:06&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;maybe there is some hidden special character in my data?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the same result if I strip out the ,000&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 12:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651055#M195290</guid>
      <dc:creator>yelkenli</dc:creator>
      <dc:date>2020-05-27T12:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: Convert char datetime to sas date format with EU format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651058#M195293</link>
      <description>&lt;P&gt;You really need to share a portion of your raw data, and the EXACT code you are running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You get 01JAN1960 because you don't have datetime values, you actually have date values, and the whole thread doesn't apply if you actually have date values. But maybe its your code that is incorrect, you do have datetime values but the wrong code. So ... share!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 12:13:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651058#M195293</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-27T12:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: Convert char datetime to sas date format with EU format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651221#M195362</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;.&amp;nbsp; Code is as above in my first post, which did not work, and then I tried the code from from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;sans the first datastep, and changing only the table and variable name in the second to point to my table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here are some of the observations in that variable (March 1rst):&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;01/03/2020 00:00:00,000&lt;BR /&gt;01/03/2020 00:00:01,000&lt;BR /&gt;01/03/2020 00:00:02,000&lt;BR /&gt;01/03/2020 00:00:03,000&lt;BR /&gt;01/03/2020 00:00:04,000&lt;BR /&gt;01/03/2020 00:00:05,000&lt;BR /&gt;01/03/2020 00:00:06,000&lt;BR /&gt;01/03/2020 00:00:07,000&lt;BR /&gt;01/03/2020 00:00:08,000&lt;BR /&gt;01/03/2020 00:00:09,000&lt;BR /&gt;01/03/2020 00:00:10,000&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268518"&gt;@DavePrinsloo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will look further at the 8601 formats.&amp;nbsp; my table is from a colleague in the EU.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 21:14:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651221#M195362</guid>
      <dc:creator>yelkenli</dc:creator>
      <dc:date>2020-05-27T21:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: Convert char datetime to sas date format with EU format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651234#M195368</link>
      <description>&lt;P&gt;With the data you gave us, the codes posted WORK. So, very obviously, your data seems to be different from what you posted.&lt;/P&gt;
&lt;P&gt;To get code that works with your&amp;nbsp;&lt;EM&gt;actual&lt;/EM&gt; data, you need to give us the dataset as-is. The PROPER way to do this is, as always, a data step with datalines. Only then will we know exactly the attributes and real contents of your dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 21:43:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651234#M195368</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-27T21:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: Convert char datetime to sas date format with EU format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651235#M195369</link>
      <description>&lt;P&gt;Look at the DATESTYLE system option. This could be why ANYDTDTM. works for some and not for others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=nlsref&amp;amp;docsetTarget=n0cmg3tjkn6zmbn1od6pna244zm7.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;https://documentation.sas.com/?docsetId=nlsref&amp;amp;docsetTarget=n0cmg3tjkn6zmbn1od6pna244zm7.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 21:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651235#M195369</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-05-27T21:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Convert char datetime to sas date format with EU format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651695#M195561</link>
      <description>&lt;P&gt;thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have ~5 million observations from a dataset that my validation team gives me.&amp;nbsp; I am not an expert at SAS, so&amp;nbsp; I simply copied and pasted a sample.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but from a more general perspective, I did not see how SAS chose US or EU date sequence (mdy or dmy) from the character variable using the any-date-time function.&amp;nbsp; It looks like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;answered that.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 12:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-datetime-to-sas-date-format-with-EU-format/m-p/651695#M195561</guid>
      <dc:creator>yelkenli</dc:creator>
      <dc:date>2020-05-29T12:25:42Z</dc:date>
    </item>
  </channel>
</rss>

