<?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 Convert SQL DateTime to SAS Date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-DateTime-to-SAS-Date/m-p/232968#M42490</link>
    <description>&lt;P&gt;I am getting the max of a DateTime column from a SQL Server table and want to compare it to a Date from a SAS data set.&lt;/P&gt;
&lt;P&gt;How do I change a SQL DateTime to a SAS date.&lt;/P&gt;
&lt;P&gt;Here is part of the code. Be kind. I'm new to SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%global &lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;Recent_Load;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;proc &lt;STRONG&gt;&lt;FONT color="#000080" size="2" face="Courier New"&gt;&lt;FONT color="#000080" size="2" face="Courier New"&gt;&lt;FONT color="#000080" size="2" face="Courier New"&gt;sql&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" size="2" face="Courier New"&gt;&lt;FONT color="#0000ff" size="2" face="Courier New"&gt;&lt;FONT color="#0000ff" size="2" face="Courier New"&gt;noprint&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;select &lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000" size="2" face="Courier New"&gt;max(Trans_Date) &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2" face="Courier New"&gt;&lt;FONT color="#0000ff" size="2" face="Courier New"&gt;&lt;FONT color="#0000ff" size="2" face="Courier New"&gt;into&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt; :Recent_Load&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;from tbl_All_Trans&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;quit&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;When I do a put of &amp;amp;Recent_Load, I get 31OCT2015:00:00:00:000&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;How do I convert this to a SAS Date with no time part.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;Terry&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Nov 2015 20:39:10 GMT</pubDate>
    <dc:creator>tstjean</dc:creator>
    <dc:date>2015-11-03T20:39:10Z</dc:date>
    <item>
      <title>Convert SQL DateTime to SAS Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-DateTime-to-SAS-Date/m-p/232968#M42490</link>
      <description>&lt;P&gt;I am getting the max of a DateTime column from a SQL Server table and want to compare it to a Date from a SAS data set.&lt;/P&gt;
&lt;P&gt;How do I change a SQL DateTime to a SAS date.&lt;/P&gt;
&lt;P&gt;Here is part of the code. Be kind. I'm new to SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%global &lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;Recent_Load;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;proc &lt;STRONG&gt;&lt;FONT color="#000080" size="2" face="Courier New"&gt;&lt;FONT color="#000080" size="2" face="Courier New"&gt;&lt;FONT color="#000080" size="2" face="Courier New"&gt;sql&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" size="2" face="Courier New"&gt;&lt;FONT color="#0000ff" size="2" face="Courier New"&gt;&lt;FONT color="#0000ff" size="2" face="Courier New"&gt;noprint&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;select &lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000" size="2" face="Courier New"&gt;max(Trans_Date) &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2" face="Courier New"&gt;&lt;FONT color="#0000ff" size="2" face="Courier New"&gt;&lt;FONT color="#0000ff" size="2" face="Courier New"&gt;into&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt; :Recent_Load&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;from tbl_All_Trans&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;quit&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;When I do a put of &amp;amp;Recent_Load, I get 31OCT2015:00:00:00:000&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;How do I convert this to a SAS Date with no time part.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT color="#000000"&gt;Terry&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Nov 2015 20:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-DateTime-to-SAS-Date/m-p/232968#M42490</guid>
      <dc:creator>tstjean</dc:creator>
      <dc:date>2015-11-03T20:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SQL DateTime to SAS Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-DateTime-to-SAS-Date/m-p/232970#M42492</link>
      <description>DATEPART() function</description>
      <pubDate>Tue, 03 Nov 2015 20:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-DateTime-to-SAS-Date/m-p/232970#M42492</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-03T20:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SQL DateTime to SAS Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-DateTime-to-SAS-Date/m-p/233062#M42534</link>
      <description>&lt;P&gt;Hi mate,&lt;/P&gt;
&lt;P&gt;You can use both, datepart() function or apply a format of date9.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global Recent_Load;
proc sql noprint;
select max(datepart(Trans_Date)) as max_date format=date9. into :Recent_Load
from tbl_All_Trans;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://v8doc.sas.com/sashtml/lrcon/zenid-63.htm" target="_blank"&gt;SAS Date, Time, and Datetime Values&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2015 13:16:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-DateTime-to-SAS-Date/m-p/233062#M42534</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2015-11-04T13:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SQL DateTime to SAS Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-DateTime-to-SAS-Date/m-p/233095#M42539</link>
      <description>&lt;P&gt;Please note that the DATEPART function, that has been suggested, requires a SAS datetime value as its argument, i.e. a numeric value in seconds from 1st Jan 1960 00:00:00. Other database systems may very well use different base dates, e.g. 1st Jan 19&lt;STRONG&gt;00&lt;/STRONG&gt;, but&amp;nbsp;I'm not familiar with "SQL Server".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I take it that your SELECT statement writes a value like &lt;SPAN&gt;31OCT2015:00:00:00:000 (or possibly rather&amp;nbsp;31OCT2015:00:00:00&lt;STRONG&gt;.&lt;/STRONG&gt;000) into&amp;nbsp;&lt;/SPAN&gt;macro variable Recent_Load. However, if variable Trans_Date was&amp;nbsp;an appropriate numeric variable containing SAS datetime values, Recent_Load would rather receive a value like&amp;nbsp;1761868800 (i.e. the SAS datetime value corresponding to&amp;nbsp;&lt;SPAN&gt;31OCT2015:00:00:00&lt;/SPAN&gt;&lt;SPAN&gt;). If, in contrast, Trans_Date is actually a character variable containing strings such as "31OCT2015:00:00:00.&lt;SPAN&gt;000", your Recent_Load value seems plausible. However, the MAX function would then have been using&amp;nbsp;&lt;U&gt;lexicographic&lt;/U&gt;&amp;nbsp;order, which would be inappropriate!&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;So, first make sure that Trans_Date is&lt;SPAN&gt;&amp;nbsp;numeric and contains SAS datetime values.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2015 15:24:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-DateTime-to-SAS-Date/m-p/233095#M42539</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-04T15:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SQL DateTime to SAS Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-DateTime-to-SAS-Date/m-p/233096#M42540</link>
      <description>&lt;P&gt;Thank you for all the suggestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2015 15:26:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SQL-DateTime-to-SAS-Date/m-p/233096#M42540</guid>
      <dc:creator>tstjean</dc:creator>
      <dc:date>2015-11-04T15:26:59Z</dc:date>
    </item>
  </channel>
</rss>

