<?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 date9. to datetime20. or vice versa using proc sql in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-date9-to-datetime20-or-vice-versa-using-proc-sql/m-p/273644#M58461</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;shared the proper approach when you need to transform a date or datetime value to perform a comparison or join within a query. &amp;nbsp;If you need a value simply for reporting though -- using a procedure other than PROC SQL -- you can use a format to "convert" a date or datetime variable into a category. &amp;nbsp;See &lt;A href="http://blogs.sas.com/content/sasdummy/2011/11/15/do-you-mind-if-we-dance-with-your-dates/" target="_self"&gt;this blog post about date and datetime formats for more information&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Fri, 27 May 2016 16:38:13 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2016-05-27T16:38:13Z</dc:date>
    <item>
      <title>How to convert date9. to datetime20. or vice versa using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-date9-to-datetime20-or-vice-versa-using-proc-sql/m-p/273412#M58446</link>
      <description>&lt;P&gt;How to convert date9. to datetime20. or vice versa using proc sql.&lt;/P&gt;&lt;P&gt;Could somebody please help me with that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 21:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-date9-to-datetime20-or-vice-versa-using-proc-sql/m-p/273412#M58446</guid>
      <dc:creator>ashwini2</dc:creator>
      <dc:date>2016-05-26T21:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date9. to datetime20. or vice versa using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-date9-to-datetime20-or-vice-versa-using-proc-sql/m-p/273420#M58448</link>
      <description>&lt;P&gt;The FORMAT only matters for display so the question is transform from date to datetime or datetime to date. If you are going to Create a datetime value from a date you need a time part. If you have no specific time you could use 0:0:0 to be midnight. That would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; create table want as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; select *, DHMS(date,0,0,0) as datetime format=datetime20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; from have;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;To extract the date from a datetime:&lt;/P&gt;
&lt;P&gt;Proc Sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; create table want as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; select *, datepart(datetime) as date format=date9.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; from have;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you think of just changing the display it will not work as SAS datetime values are recorded in seconds and dates are in Days. So the functions DHMS and Datepart are the main ways to do transforms. You can specify the time if you have actual hour, minute second value by DHMS(date, hour, minute,second). If you have a separate actual time value then DHMS(date,0,0,time) as time should be the correct number of seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 16:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-date9-to-datetime20-or-vice-versa-using-proc-sql/m-p/273420#M58448</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-27T16:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date9. to datetime20. or vice versa using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-date9-to-datetime20-or-vice-versa-using-proc-sql/m-p/273644#M58461</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;shared the proper approach when you need to transform a date or datetime value to perform a comparison or join within a query. &amp;nbsp;If you need a value simply for reporting though -- using a procedure other than PROC SQL -- you can use a format to "convert" a date or datetime variable into a category. &amp;nbsp;See &lt;A href="http://blogs.sas.com/content/sasdummy/2011/11/15/do-you-mind-if-we-dance-with-your-dates/" target="_self"&gt;this blog post about date and datetime formats for more information&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 16:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-date9-to-datetime20-or-vice-versa-using-proc-sql/m-p/273644#M58461</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2016-05-27T16:38:13Z</dc:date>
    </item>
  </channel>
</rss>

