<?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: How to convert a character datetime to a date MM/DD/YYY in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551450#M153226</link>
    <description>&lt;P&gt;When you export sas data to excel, a sas numeric date will be transferred to excel as excel numeric date&lt;/P&gt;
&lt;P&gt;but you can't force excel - to display date in a specified format - by sas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Apr 2019 16:47:33 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2019-04-16T16:47:33Z</dc:date>
    <item>
      <title>How to convert a character datetime to a date MM/DD/YYY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551420#M153204</link>
      <description>&lt;P&gt;Hi - Need a bit of help - &amp;nbsp;I have a dataset that has 10,000+ rows, there's a variable that's a character datetime $19. format&amp;nbsp;that needs to be converted to a true date format when exported to Excel&amp;nbsp;formatted as MM/DD/YYYY.&amp;nbsp;&lt;/P&gt;&lt;P&gt;example of character datetime: 2017-07-21 00:00:00&lt;/P&gt;&lt;P&gt;Needs to be a date: 07/21/2017&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried a couple of things, however no success yet - Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 15:36:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551420#M153204</guid>
      <dc:creator>ScotchCat</dc:creator>
      <dc:date>2019-04-16T15:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character datetime to a date MM/DD/YYY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551425#M153208</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210216"&gt;@ScotchCat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi - Need a bit of help - &amp;nbsp;I have a dataset that has 10,000+ rows, there's a variable that's a character datetime $19. format&amp;nbsp;that needs to be converted to a true date format when exported to Excel&amp;nbsp;formatted as MM/DD/YYYY.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example of character datetime: 2017-07-21 00:00:00&lt;/P&gt;
&lt;P&gt;Needs to be a date: 07/21/2017&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried a couple of things, however no success yet - Thanks in advance!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It often helps to show what you tried that did not work so we can provide reasons why.&lt;/P&gt;
&lt;P&gt;A very common mistake is trying to do the conversion of character to date (which is numeric) into the same variable. Once the variable is created SAS will not allow you to actually change the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should be able to get a date value from the character you show as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;datevar = input(datetime,yymmdd10.);&lt;/P&gt;
&lt;P&gt;and then you will want a FORMAT to apply the desired appearance as&lt;/P&gt;
&lt;P&gt;format datevar mmddyy10.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint: Make sure that the initial reading of data into SAS has the desired properties. That will save much time later.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 15:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551425#M153208</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-16T15:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character datetime to a date MM/DD/YYY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551429#M153211</link>
      <description>&lt;P&gt;I tried this and the Datetime character stays the same - no change:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Have; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;NewDate = input(Datetime,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;yymmdd10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; NewDate &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;mmddyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 15:54:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551429#M153211</guid>
      <dc:creator>ScotchCat</dc:creator>
      <dc:date>2019-04-16T15:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character datetime to a date MM/DD/YYY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551450#M153226</link>
      <description>&lt;P&gt;When you export sas data to excel, a sas numeric date will be transferred to excel as excel numeric date&lt;/P&gt;
&lt;P&gt;but you can't force excel - to display date in a specified format - by sas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 16:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551450#M153226</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-04-16T16:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character datetime to a date MM/DD/YYY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551451#M153227</link>
      <description>&lt;P&gt;Here's a simple example, you'll need to adjust it for your situation&lt;BR /&gt;Basically I create a string variable (cDateTime), convert that to a SAS date time value (sasDateTime), extract the date part (sasDate) and finally print all the variables, both in their raw form and formatted.&lt;BR /&gt;&lt;BR /&gt;Please refer to the documentation on SAS &lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=leforinforref&amp;amp;docsetTarget=p0z62k899n6a7wn1r5in6q5253v1.htm&amp;amp;locale=en" target="_self"&gt;Formats&lt;/A&gt; and Informats&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
	infile cards ;
	input cDateTime $19. ;
	sasDateTime=inputn(cDateTime,"datetime.") ;
	sasDate=datepart(sasDateTime) ;
	put cDateTime= sasDateTime= sasDateTime= datetime. sasDate= sasDate= date. ;

cards;
04APR2019 14:35
06APR2019 06:45
;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Apr 2019 16:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551451#M153227</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2019-04-16T16:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character datetime to a date MM/DD/YYY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551456#M153230</link>
      <description>&lt;P&gt;Thanks Shmuel, however after running the suggested code&amp;nbsp;the dataset in SAS didn't update to a date and remained a character.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 17:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551456#M153230</guid>
      <dc:creator>ScotchCat</dc:creator>
      <dc:date>2019-04-16T17:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a character datetime to a date MM/DD/YYY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551487#M153235</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210216"&gt;@ScotchCat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I tried this and the Datetime character stays the same - no change:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Want;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Have; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;NewDate = input(Datetime,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;yymmdd10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; NewDate &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;mmddyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I think that you need to provide some actual example of your HAVE data set.&lt;/P&gt;
&lt;P&gt;This works just fine:&lt;/P&gt;
&lt;PRE&gt;data example;
   x='2017-07-21 00:00:00';
   y= input(x,yymmdd10.);
   format y date9.;
run;&lt;/PRE&gt;
&lt;P&gt;You code might not work if you have 1) leading spaces in your datetime variable, 2) your actual value is a SAS datetime value&amp;nbsp;and you only think it is character or 3) some other headache with the actual values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 17:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-a-character-datetime-to-a-date-MM-DD-YYY/m-p/551487#M153235</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-16T17:53:47Z</dc:date>
    </item>
  </channel>
</rss>

