<?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 date with time from character format to numeric date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700613#M214425</link>
    <description>&lt;P&gt;Hmm,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's go in piecemeal-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First try without assigning a format-&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;char_dt='2019-01-16T14:03';
num_dt=input(char_dt,yymmdd10.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See, what you get for num_dt. You should see some numbers(integers). These are SAS date numbers. If you do not see these numbers, you got to check your character pattern. The pattern assumes the first 10 characters of char_dt is in the form yyyy-mm-dd i.e. readable by the informat yymmdd10. I hope this should make sense to you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;char_dt='2019-01-16T14:03';
num_dt=input(char_dt,yymmdd10.);
format num_dt mmddyy10.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With format being assigned, you should be able to see this&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.W" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;char_dt&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;num_dt&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;2019-01-16T14:03&lt;/TD&gt;
&lt;TD class="r data"&gt;01/16/2019&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;If the above is a success, you should the try assigning a format to the number dates for display&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Nov 2020 21:19:08 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-11-20T21:19:08Z</dc:date>
    <item>
      <title>convert date with time from character format to numeric date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700603#M214418</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I'm trying to figure out how to convert this date with time (character) to date without time(&amp;nbsp;numeric). Any help is greatly appreciated!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EXENDTC&amp;nbsp; &amp;nbsp;2019-01-16T14:03&amp;nbsp; --&amp;gt;&amp;nbsp;2019-01-16&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 20:42:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700603#M214418</guid>
      <dc:creator>Amy0223</dc:creator>
      <dc:date>2020-11-20T20:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: convert date with time from character format to numeric date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700604#M214419</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data test;
char_dt='2019-01-16T14:03';
num_dt=input(char_dt,yymmdd10.);
format num_dt mmddyy10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Basically, the idea is to read the 1st 10 bytes of characters with the appropriate date informat and convert to a numeric date.&lt;/P&gt;
&lt;P&gt;Then you could just format the numeric date value with any FORMAT you like&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 20:49:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700604#M214419</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-20T20:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: convert date with time from character format to numeric date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700609#M214421</link>
      <description>Thanks for your quick response. When I tried it, I got this note for format num_dt mmddyy10.;            &lt;BR /&gt;NOTE 484-185: Format $MMDDYY was not found or could not be loaded.&lt;BR /&gt;&lt;BR /&gt;Could you  give some suggestions on how to resolve it? Thanks!&lt;BR /&gt;</description>
      <pubDate>Fri, 20 Nov 2020 20:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700609#M214421</guid>
      <dc:creator>Amy0223</dc:creator>
      <dc:date>2020-11-20T20:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: convert date with time from character format to numeric date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700610#M214422</link>
      <description>&lt;P&gt;&lt;SPAN&gt;NOTE 484-185: Format $MMDDYY was not found or could not be loaded.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Are you sure you used &lt;STRONG&gt;MMDDYY10.&lt;/STRONG&gt; format or&amp;nbsp;&lt;STRONG&gt; $&lt;/STRONG&gt;MMDDYY?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Not sure what you wrote in the code.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also, are you sure your datetime value is stored as &lt;STRONG&gt;character?&amp;nbsp;&lt;/STRONG&gt;Did you check that out using PROC CONTENTS?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 21:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700610#M214422</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-20T21:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: convert date with time from character format to numeric date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700612#M214424</link>
      <description>&lt;P&gt;Yes,&amp;nbsp;EXENDTC is a character with&amp;nbsp;$26. and I used&amp;nbsp;MMDDYY10. but the note says&amp;nbsp;&amp;nbsp;$MMDDYY. I'm not sure why but thank you again for your help. I really appreciate it!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 21:09:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700612#M214424</guid>
      <dc:creator>Amy0223</dc:creator>
      <dc:date>2020-11-20T21:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: convert date with time from character format to numeric date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700613#M214425</link>
      <description>&lt;P&gt;Hmm,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's go in piecemeal-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First try without assigning a format-&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;char_dt='2019-01-16T14:03';
num_dt=input(char_dt,yymmdd10.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See, what you get for num_dt. You should see some numbers(integers). These are SAS date numbers. If you do not see these numbers, you got to check your character pattern. The pattern assumes the first 10 characters of char_dt is in the form yyyy-mm-dd i.e. readable by the informat yymmdd10. I hope this should make sense to you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;char_dt='2019-01-16T14:03';
num_dt=input(char_dt,yymmdd10.);
format num_dt mmddyy10.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With format being assigned, you should be able to see this&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.W" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;char_dt&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;num_dt&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;2019-01-16T14:03&lt;/TD&gt;
&lt;TD class="r data"&gt;01/16/2019&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;If the above is a success, you should the try assigning a format to the number dates for display&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 21:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700613#M214425</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-20T21:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: convert date with time from character format to numeric date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700615#M214426</link>
      <description>&lt;P&gt;And another alternative is, using YMDDTTM informat. However this one converts your character datetime value to a numeric datetime value, which means you would need to extract the DATEPART value from a DATETIME value using datepart function and then apply the date format of your choice.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
char_dt='2019-01-16T14:03';
num_dt=datepart(input(char_dt,ymddttm24.));
format num_dt mmddyy10.;
run;
proc print noobs;run;&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 21:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700615#M214426</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-20T21:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: convert date with time from character format to numeric date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700617#M214428</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265801"&gt;@Amy0223&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes,&amp;nbsp;EXENDTC is a character with&amp;nbsp;$26. and I used&amp;nbsp;MMDDYY10. but the note says&amp;nbsp;&amp;nbsp;$MMDDYY. I'm not sure why but thank you again for your help. I really appreciate it!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since you have EXENDTC with a $26 format and the length of a value like 2019-01-16T14:03 is 16 characters it may be that you have one or more leading spaces which would prevent the informat from working.&lt;/P&gt;
&lt;P&gt;Example, the log will show the values.&lt;/P&gt;
&lt;PRE&gt;data example;
   v1 = "2019-01-16T14:03          ";
   v2 = "          2019-01-16T14:03";
   length1 = length(v1);
   length2 = length(v2);
   put length1= length2=;
   d1 = input(v1,yymmdd10.);
   d2 = input(v2,yymmdd10.);
   put d1 = mmddyy10. d2 = yymmdd10.;
run;&lt;/PRE&gt;
&lt;P&gt;If you do a similar length check and find some values have leading spaces you can use&lt;/P&gt;
&lt;P&gt;input(strip(variablename), yymmdd10.)&lt;/P&gt;
&lt;P&gt;so the leading spaces are ignored for the input function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A not about $mmddyy means you attempted to use the format on a character variable. Which means you need to show the actual code. Copy from the log the data step and all the notes, paste into a code box opened with the &amp;lt;/&amp;gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do need to create a new variable, you cannot change the type of a variable in SAS once it has been created. So if you attempted to do something like: EXENDTC = input(EXENDTC, yymmdd10) that is right out.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 21:34:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-with-time-from-character-format-to-numeric-date/m-p/700617#M214428</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-20T21:34:40Z</dc:date>
    </item>
  </channel>
</rss>

