<?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 Comparing two dates in different tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-two-dates-in-different-tables/m-p/92277#M19472</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone help me with this please?&lt;/P&gt;&lt;P&gt;I have two tables with dates in each and need to compare the two dates, when comparing I also need to count where the difference between the two dates is within 30 seconds of each another.&lt;/P&gt;&lt;P&gt;The two tables have tens of tousands of dates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas how to do this please?&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;Zubair&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 11 Oct 2012 11:47:11 GMT</pubDate>
    <dc:creator>bob2012</dc:creator>
    <dc:date>2012-10-11T11:47:11Z</dc:date>
    <item>
      <title>Comparing two dates in different tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-two-dates-in-different-tables/m-p/92277#M19472</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone help me with this please?&lt;/P&gt;&lt;P&gt;I have two tables with dates in each and need to compare the two dates, when comparing I also need to count where the difference between the two dates is within 30 seconds of each another.&lt;/P&gt;&lt;P&gt;The two tables have tens of tousands of dates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas how to do this please?&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;Zubair&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 11:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-two-dates-in-different-tables/m-p/92277#M19472</guid>
      <dc:creator>bob2012</dc:creator>
      <dc:date>2012-10-11T11:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two dates in different tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-two-dates-in-different-tables/m-p/92278#M19473</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Zubair,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, I assume you mean date-time variables, not dates.&lt;/P&gt;&lt;P&gt;The direct way is with SQL.&amp;nbsp; However, it requires multiple passes of the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&amp;nbsp; * untested code;&lt;/P&gt;&lt;P&gt;SELECT count(*) &lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM a, b&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHERE a.datetime BETWEEN b.datetime - 30 AND b.datetime+30;&lt;/P&gt;&lt;P&gt;&amp;nbsp; QUIT;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This would give a count of the number of a.datetime's that are within 30 seconds of any b.datetime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Somehow, I don't really think that is what your question is.&amp;nbsp; Perhaps you could post a sample of the data you have and the results you want.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 13:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-two-dates-in-different-tables/m-p/92278#M19473</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2012-10-11T13:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two dates in different tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-two-dates-in-different-tables/m-p/92279#M19474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Doc,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for responding!&lt;/P&gt;&lt;P&gt;Yes, I'm comparing date time variables and not dates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please see attached a sample of the data I'm working with.&lt;/P&gt;&lt;P&gt;I'd like to compare Date Modified (DM) to Event Date (ED) and check if the difference in seconds between the two is greater than 30. At the same time I need to count by Country code.&lt;/P&gt;&lt;P&gt;So, for example, the result for DM obs1 (30/09/2012 09:45:10) would be UK = 1 and US = 1.&lt;/P&gt;&lt;P&gt;The step would then compare DM obs 2 with all the records in ED.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Obs&amp;nbsp; Date_Modified&lt;BR /&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/09/2012 09:45:10&lt;BR /&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/09/2012 09:46:15&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/09/2012 08:58:20&lt;BR /&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/09/2012 09:03:25&lt;BR /&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/09/2012 09:15:30&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Obs&amp;nbsp;&amp;nbsp; Event_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Country&lt;BR /&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/9/2012 09:45:32&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UK&lt;BR /&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/9/2012 09:51:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; US&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/9/2012 09:45:27&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; US&lt;BR /&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/9/2012 09:56:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UK&lt;BR /&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 29/9/2012 09:45:15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; US&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does this help?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Zubair&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 13:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-two-dates-in-different-tables/m-p/92279#M19474</guid>
      <dc:creator>bob2012</dc:creator>
      <dc:date>2012-10-11T13:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two dates in different tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-two-dates-in-different-tables/m-p/92280#M19475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well.. Following is one way.. . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;add one rownum column to each dataset temporarily.. &lt;/P&gt;&lt;P&gt;merge those by rownum..&lt;/P&gt;&lt;P&gt;keep only required columns&lt;/P&gt;&lt;P&gt;if (abs(date1-date2)&amp;gt;=30) then output;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 18:49:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-two-dates-in-different-tables/m-p/92280#M19475</guid>
      <dc:creator>acerishi</dc:creator>
      <dc:date>2012-10-11T18:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two dates in different tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-two-dates-in-different-tables/m-p/92281#M19476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Doc is right.SQL may require multiple steps.&lt;/P&gt;&lt;P&gt;And this is to be taken in account when you are dealing with ten of thousands of observations and want to compare all observations from one dataset with all observations from another dataset. This is what we call a cartesian product. "Cartesian Product, you must be out of your mind", some may say.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Still, I like the SQL approach.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's say A is your first dataset and B the second. I would adapt Doc's code like this&lt;/P&gt;&lt;P&gt;PROC SQL;&amp;nbsp; * untested code;&lt;/P&gt;&lt;P&gt;CREATE TABLE step1 AS&lt;/P&gt;&lt;P&gt;SELECT A.Date_Modified, B.Country,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CASE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN&amp;nbsp; A.Date_Modified BETWEEN B.Event_date-'0:0:30't AND B.Event_date+'0:0:30't then 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) AS Nb_Selected &lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM A, B&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;This would give a table like this&lt;/P&gt;&lt;P&gt;Date_Modified&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Country&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Nb_Selected&lt;/P&gt;&lt;P&gt;30/09/2012 09:45:10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;30/09/2012 09:45:10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; US&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;You may want to test this code with a sample, lets'say 1000 obs from each table with the PROC SQL INOBS options :&lt;/P&gt;&lt;P&gt;PROC SQL INOBS=1000;&lt;/P&gt;&lt;P&gt;If the intermediary result is not necessary, you may want to CREATE VIEW step1 instead of CREATE TABLE step1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next, you'll have to transpose the intermediary result&lt;/P&gt;&lt;P&gt;PROC TRANSPOSE DATA=step1 OUT=result NAME=Country;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VAR Nb_Selected;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;to get what you want&lt;/P&gt;&lt;P&gt;Date_Modified&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; US&lt;/P&gt;&lt;P&gt;30/09/2012 09:45:10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 21:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-two-dates-in-different-tables/m-p/92281#M19476</guid>
      <dc:creator>tlt</dc:creator>
      <dc:date>2012-10-11T21:07:30Z</dc:date>
    </item>
  </channel>
</rss>

