<?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: Problems with datetime conversion in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Problems-with-datetime-conversion/m-p/77128#M22352</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;proc format;
 picture fmt
&amp;nbsp; other='%Y/%m/%d %0H:%0M' (datatype=datetime);
run;
data _null_;
 a='01JAN10:17:00:00'dt;
 b='01APR09:17:00:00'dt;
 want=put(a-intck('dtseconds',b,a),fmt21.);
 put want=;
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 26 Sep 2012 06:10:11 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2012-09-26T06:10:11Z</dc:date>
    <item>
      <title>Problems with datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problems-with-datetime-conversion/m-p/77126#M22350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having problems with merging datasets with different formats of date&amp;amp; time. :smileyplain:&lt;/P&gt;&lt;P&gt;Most of the datasets' date&amp;amp;time data look like 2009/4/1 17:00 (character type $14. in one column), but two datasets' date&amp;amp;time values look like&lt;/P&gt;&lt;P&gt;01JAN10:17:00:00 (DATETIME, numeric type).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way that I can convert the datetime data from&lt;STRONG&gt; 01JAN10:17:00:00 (DATETIME, numeric type)&lt;/STRONG&gt; to&amp;nbsp; &lt;STRONG&gt;2009/4/1 17:00 (character type $14.)&lt;/STRONG&gt;?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chin &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Sep 2012 03:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problems-with-datetime-conversion/m-p/77126#M22350</guid>
      <dc:creator>Chi</dc:creator>
      <dc:date>2012-09-26T03:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problems-with-datetime-conversion/m-p/77127#M22351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It would be better to convert the text string to an actual datetime value if you want to be able to use them for merging.&lt;/P&gt;&lt;P&gt;Let's assume that your character variable that looks like a datetime value is named DATETIMEC and you want to create a new variable named DATETIME.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; datetime=input(datetimec,anydtdtm.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; format datetime datetime.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that $14 is too short to store all possible values in YYYY/MM/DD HH:MM format. That would require 16 characters.&lt;/P&gt;&lt;P&gt;Note also that if you store datetimes as character strings without the leading zeros for month,day and hour then it will not sort in chronological order.&lt;/P&gt;&lt;P&gt;But given those problems if you did want to convert an actual datetime value to that format you could do it using PUT functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; length datetimec $16;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; datetimec=put(datepart(datetime),yymmdds10.)||' '||put(timepart(datetime),time5.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Sep 2012 03:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problems-with-datetime-conversion/m-p/77127#M22351</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-09-26T03:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problems-with-datetime-conversion/m-p/77128#M22352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;proc format;
 picture fmt
&amp;nbsp; other='%Y/%m/%d %0H:%0M' (datatype=datetime);
run;
data _null_;
 a='01JAN10:17:00:00'dt;
 b='01APR09:17:00:00'dt;
 want=put(a-intck('dtseconds',b,a),fmt21.);
 put want=;
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Sep 2012 06:10:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problems-with-datetime-conversion/m-p/77128#M22352</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-09-26T06:10:11Z</dc:date>
    </item>
  </channel>
</rss>

