<?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 How to compare two different datetime values in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/399912#M278558</link>
    <description>&lt;P&gt;So here is the deal, I have two SQL Server Tables (A &amp;amp; B) which I want to merge using Proc sql.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table A has variable datetime_A and Table B has variable datetime_B.&amp;nbsp;&lt;/P&gt;&lt;P&gt;datetime_A format : yyyy-mm-dd hh:mm:ss:mil&lt;/P&gt;&lt;P&gt;datetme_B format:&amp;nbsp;&lt;SPAN&gt;yyyy-mm-dd hh:mm:ss&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Further, the datetime_A is accurate to the milliseconds and datetime_B has its seconds rounded (which means the seconds are always 00)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In essence i want to compare only till the minutes part. I figured I will have to somehow convert the datetime to a char or varchar till the minutes part and compare the two in my join clause.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm unable to arrive at the correct syntax to do the same.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Sep 2017 20:11:32 GMT</pubDate>
    <dc:creator>cruzerkk</dc:creator>
    <dc:date>2017-09-29T20:11:32Z</dc:date>
    <item>
      <title>How to compare two different datetime values in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/399912#M278558</link>
      <description>&lt;P&gt;So here is the deal, I have two SQL Server Tables (A &amp;amp; B) which I want to merge using Proc sql.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table A has variable datetime_A and Table B has variable datetime_B.&amp;nbsp;&lt;/P&gt;&lt;P&gt;datetime_A format : yyyy-mm-dd hh:mm:ss:mil&lt;/P&gt;&lt;P&gt;datetme_B format:&amp;nbsp;&lt;SPAN&gt;yyyy-mm-dd hh:mm:ss&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Further, the datetime_A is accurate to the milliseconds and datetime_B has its seconds rounded (which means the seconds are always 00)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In essence i want to compare only till the minutes part. I figured I will have to somehow convert the datetime to a char or varchar till the minutes part and compare the two in my join clause.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm unable to arrive at the correct syntax to do the same.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2017 20:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/399912#M278558</guid>
      <dc:creator>cruzerkk</dc:creator>
      <dc:date>2017-09-29T20:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two different datetime values in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/399919#M278559</link>
      <description>&lt;P&gt;If you're dealing with SAS datetime values then it's the numbers of second after midnight Jan 1, 1960.&amp;nbsp; If milliseconds are 000, then the datetime value is an integer.&amp;nbsp; The milliseconds are just the non-integer component of the datetime.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So just match&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; datetime_b&lt;/P&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int(datetime_a)&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2017 20:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/399919#M278559</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-09-29T20:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two different datetime values in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/400694#M278560</link>
      <description>1) I'm dealing with Datetime values in SQL which I am bringing into SAS through proc SQL.&amp;nbsp;&lt;BR /&gt;2) I want to compare only till minutes, in other words, if datetime_A = 2017-01-13 11:28:11.477&lt;BR /&gt;&amp;amp; datetime_B = 2017-01-13 11:28:00. I want the match to be true.</description>
      <pubDate>Tue, 03 Oct 2017 18:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/400694#M278560</guid>
      <dc:creator>cruzerkk</dc:creator>
      <dc:date>2017-10-03T18:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two different datetime values in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/400712#M278561</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you asking an SQL server question in a SAS forum?&amp;nbsp;&amp;nbsp;Are you employing pass-through code?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 18:32:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/400712#M278561</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-03T18:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two different datetime values in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/400718#M278562</link>
      <description>I am asking if there is a way to manipulate incoming data from sql server on the sas side. I do not have access to the sql server to do the manipulation there.&lt;BR /&gt;This is probably what I would have done in the SQL Server Side:&lt;BR /&gt;select * from A inner join B on&lt;BR /&gt;CONVERT(VARCHAR(16), datetime_A ) = CONVERT(VARCHAR(16), datetime_B )&lt;BR /&gt;&lt;BR /&gt;But the 'CONVERT' function does not work in proc sql. Is there a corresponding implementation in SAS ?&lt;BR /&gt;</description>
      <pubDate>Tue, 03 Oct 2017 18:37:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/400718#M278562</guid>
      <dc:creator>cruzerkk</dc:creator>
      <dc:date>2017-10-03T18:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two different datetime values in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/400727#M278563</link>
      <description>&lt;P&gt;I have never used SAS access to sql server, but I thought that&amp;nbsp;if sql server metadata specifies a variable as SQL DATETIME (apparently 2 4-byte integers in an 8-byte value, according to a quick google search), it would be recognized by PROC SQL, and consequently the value would be converted to SAS datetime value.&amp;nbsp; If so, then the milliseconds would merely be the non-integer portion of the value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you extract a row with a known SQL Server datetime value, and then apply a SAS&amp;nbsp;&amp;nbsp; datatime27.3 format to it, do you get the expected display of date and time?&amp;nbsp; If so, then my conjecture on sas/access to sql server is apparently correct, and you can use the INT function in SAS to remove the sub-second component.&amp;nbsp; No doubt someone&amp;nbsp; with direct&amp;nbsp; experience can cite chapter and verse on this, alleviating the need for my experiment.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 18:46:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/400727#M278563</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-03T18:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two different datetime values in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/400801#M278564</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/149136"&gt;@cruzerkk&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;When joining two database tables using SQL syntax formulated in the SAS SQL flavor then the SAS/Access engine will try and push as much of this SQL to the database for processing. If using SAS only functions in the SQL then SAS won't be able to push a lot of the SQL but will have to pull all the data from the database to SAS for processing which can be quite an overhead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Within SAS&lt;/P&gt;
&lt;P&gt;SAS DateTime values are the count of seconds starting from 1/1/1960. This count is stored in a SAS variable of type Numeric and you can use it for calculations. So to find two SAS DateTime values within 60 seconds: abs(DTTM_Var1 - DTTM_Var2)&amp;lt;60&lt;/P&gt;
&lt;P&gt;There are multiple approaches possible to find values with the same number of minutes: You can use intnx() to align the values to the beginning of the minute and then compare, you can divide by 100, use int() and compare, or you can convert the values to a character up to the minute using a put(&amp;lt;var&amp;gt;, &amp;lt;format&amp;gt;) and compare.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...BUT: To avoid the overhead for SAS having to pull all the data on its side: You can also use explicit SQL pass-through and write the whole SQL in the database flavor using database functions and then only pull the result set into SAS for further processing (if you need it there at all).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 20:46:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/400801#M278564</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-03T20:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two different datetime values in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/400888#M278565</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/149136"&gt;@cruzerkk&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;You could use the ROUND function to round datetime_A to the nearest minute - as others have already pointed out, the SAS datetime value is number of seconds, so rounding to the nearest 60 will get you the minutes, e.g.:&lt;/P&gt;&lt;PRE&gt;select 
  &amp;lt;columns&amp;gt;
from 
  &amp;lt;sqlserver table A&amp;gt; a 
join 
  &amp;lt;sqlserver table B&amp;gt; b
on
  b.&amp;lt;datetime variable&amp;gt;=round(a.&amp;lt;datetime variable&amp;gt;,60)&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Oct 2017 09:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-two-different-datetime-values-in-proc-sql/m-p/400888#M278565</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-10-04T09:56:12Z</dc:date>
    </item>
  </channel>
</rss>

