<?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 DATETIME20. TO MM/DD/YYYY HH:MM:SS  ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Convert-DATETIME20-TO-MM-DD-YYYY-HH-MM-SS/m-p/272757#M269523</link>
    <description>&lt;P&gt;When I run this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data junk;
   x=  '02MAY2016:21:29:38'dt;
   put x mdyhms.;
   format x mdyhms.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The value in the dataset appears as desired and the output in the log. The value you show is the correct value for the datetime variable. Perhaps you have a spelling issue with the name of your variable on the format statement? Do you get a message about an uninitialized variable in the log?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 May 2016 15:07:41 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-05-24T15:07:41Z</dc:date>
    <item>
      <title>How to Convert DATETIME20. TO MM/DD/YYYY HH:MM:SS  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Convert-DATETIME20-TO-MM-DD-YYYY-HH-MM-SS/m-p/272752#M269522</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;I am trying to convert Datetime format of a variable from dataset&amp;nbsp;from DATETIME20.(02MAY2016:21:29:38) to mm/dd/yyyy hh:mm:ss .&lt;/P&gt;
&lt;P&gt;Tried to use below PROC FORMAT code but its not working as expected .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;format&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;picture&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; mdyhms&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; other = &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'%0m/%0d/%Y %0H:%0M:%0S'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datatype&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;=datetime);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;DATA DATASET2;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET DATASET1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;FORMAT DATEVARIABLE MDYHMS.;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;RESULTS:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;INPUT(IN DATASET1)&amp;nbsp;: &amp;nbsp;02MAY2016:21:29:38&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;OUTPUT(IN DATSET2) :&amp;nbsp;&amp;nbsp;1777843778&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;DESIRED OUTPUT(IN DATASET2) : 05/02/2016 21:29:38 &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2016 14:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Convert-DATETIME20-TO-MM-DD-YYYY-HH-MM-SS/m-p/272752#M269522</guid>
      <dc:creator>Dob4Die</dc:creator>
      <dc:date>2016-05-24T14:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to Convert DATETIME20. TO MM/DD/YYYY HH:MM:SS  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Convert-DATETIME20-TO-MM-DD-YYYY-HH-MM-SS/m-p/272757#M269523</link>
      <description>&lt;P&gt;When I run this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data junk;
   x=  '02MAY2016:21:29:38'dt;
   put x mdyhms.;
   format x mdyhms.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The value in the dataset appears as desired and the output in the log. The value you show is the correct value for the datetime variable. Perhaps you have a spelling issue with the name of your variable on the format statement? Do you get a message about an uninitialized variable in the log?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2016 15:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Convert-DATETIME20-TO-MM-DD-YYYY-HH-MM-SS/m-p/272757#M269523</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-24T15:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to Convert DATETIME20. TO MM/DD/YYYY HH:MM:SS  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Convert-DATETIME20-TO-MM-DD-YYYY-HH-MM-SS/m-p/272758#M269524</link>
      <description>&lt;P&gt;I think you got it right! &amp;nbsp;When I tried&amp;nbsp;the&amp;nbsp;code, the format was&amp;nbsp;producing the desired output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Internally,&amp;nbsp;sas&amp;nbsp;dates (and &lt;SPAN&gt;datetimes)&amp;nbsp;&lt;/SPAN&gt;are&amp;nbsp;always represented as numbers (the format will not change that.) &amp;nbsp;But when printing/displaying the value,&amp;nbsp;the format should&amp;nbsp;render the output just&amp;nbsp;as you expect it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You may also apply your format to convert the numeric datetime to a string (see example below, using the put function.) Maybe that is what you were looking for. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture mdyhms other = '%0m/%0d/%Y %0H:%0M:%0S' (datatype=datetime);
run;
 
data dataset2;
	format datevariable mdyhms.;
	datevariable = 1777843778;
	datevariable_string = put(datevariable, mdyhms.);
run;

proc print data=dataset2 noobs; 
run;

/* OUTPUT:  */
/* datevariable         datevariable_string  */
/* 05/02/2016 21:29:38  05/02/2016 21:29:38  */&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2016 15:16:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Convert-DATETIME20-TO-MM-DD-YYYY-HH-MM-SS/m-p/272758#M269524</guid>
      <dc:creator>carlosmirandad</dc:creator>
      <dc:date>2016-05-24T15:16:04Z</dc:date>
    </item>
  </channel>
</rss>

