<?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: proc sql join where date = date + 1 day in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231417#M54575</link>
    <description>&lt;P&gt;Pg, thanks, it wokrs very well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But i have one question, i work in a bank and the table i'm using has some transactions that occur in same time of the other.&lt;/P&gt;
&lt;P&gt;Just like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A Guy make a transaction in 12aug205:12:45:00&lt;/P&gt;
&lt;P&gt;And then the same guy make another transaction with same value and datetime of the first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would those lines be duplicated ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tks&lt;/P&gt;</description>
    <pubDate>Fri, 23 Oct 2015 17:58:49 GMT</pubDate>
    <dc:creator>DartRodrigo</dc:creator>
    <dc:date>2015-10-23T17:58:49Z</dc:date>
    <item>
      <title>proc sql join where date = date + 1 day</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231390#M54566</link>
      <description>&lt;P&gt;Hi mates,&lt;/P&gt;
&lt;P&gt;I'm trying to make a join where some of my dates are as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;date of table 1 = 12apr2015:00:23:46&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;date of table 2 = 13apr2015:00:23:46&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I'd like to join these table in condition just like d1.date = d2.date + 1*24*60*60(one more day).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But consider that some dates are the same in both tables but sometimes they don't.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In fact the join should match in both cases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code to test is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines4;
format date date9.;
input ID$     VISIT     value1     value2     value3   date:date9. ;
datalines4; 
A     1     5     7     9   16jan2015
A     2     .     .      .  14feb2015
A     3     .     .      .  27mar2015
A     4     10     5     3  17apr2015
A     5     .     .      .  17may2015
B     1     11     2     6  18jun2015
B     2     .      .     .  19jul2015
B     3     16     7     9  10aug2015
B     4     .      .     .  11sep2015
B     5     18     20     5 17oct2015
;;;;;;
run;

%macro date(num);
data want;
set have;
  %do i =1 %to 3;
    if value&amp;amp;&amp;amp;i. = . then value&amp;amp;&amp;amp;i.=0;
  %end;
run;
%mend;
%date(3);

data last;
   infile datalines4;
   format date date9.;
input x$  date:date9.;
datalines4;
A 17jan2015
A 15feb2015
A 28mar2015
A 18apr2015
A 18may2015
B 19jun2015
B 20jul2015
B 11aug2015
B 12sep2015
B 17oct2015
;;;;;;
run;

proc sql;
   create table final as 
      select *
				from want as w 
	  			right join last as l on (w.date=l.date);
quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;How can i fix this ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks before any answer&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 16:47:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231390#M54566</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2015-10-23T16:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql join where date = date + 1 day</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231394#M54567</link>
      <description>&lt;P&gt;Do you want to match SAS dates or SAS datetimes? Your question seems to be about datetimes but your example involves only SAS dates.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 16:56:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231394#M54567</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-23T16:56:49Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql join where date = date + 1 day</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231395#M54568</link>
      <description>&lt;P&gt;Datetimes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tks&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 16:58:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231395#M54568</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2015-10-23T16:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql join where date = date + 1 day</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231398#M54570</link>
      <description>&lt;P&gt;For the example data you have the solution will work.&amp;nbsp; I didn't test with datetime but if the real data is datetime I would try the commented out line.&amp;nbsp; If the dataset is very large it might be better add a new variable with the datepart already derived because the join will do this over and over again for every record:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table final as&lt;BR /&gt;select a.*,b.date as date_b&lt;BR /&gt;from want a inner join&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last b on&lt;BR /&gt;/*a.date = intnx('day',datepart(b.date),-1,'same');*/&lt;BR /&gt;a.date = b.date -1;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 17:10:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231398#M54570</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-10-23T17:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql join where date = date + 1 day</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231400#M54571</link>
      <description>&lt;P&gt;I rebuilt your example so that it involves datetimes only. It is not clear whether you want/need to match times exactly. I assumed not:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format date datetime.;
input ID$     VISIT     value1     value2     value3   d:date9. ;
date = dhms(d,0,0,0);
drop d;
datalines; 
A     1     5     7     9   16jan2015
A     2     .     .      .  14feb2015
A     3     .     .      .  27mar2015
A     4     10     5     3  17apr2015
A     5     .     .      .  17may2015
B     1     11     2     6  18jun2015
B     2     .      .     .  19jul2015
B     3     16     7     9  10aug2015
B     4     .      .     .  11sep2015
B     5     18     20     5 17oct2015
;


data last;
format date datetime.;
input ID$  d:date9.;
date = dhms(d,0,0,0);
drop d;
datalines;
A 17jan2015
A 15feb2015
A 28mar2015
A 18apr2015
A 18may2015
B 19jun2015
B 20jul2015
B 11aug2015
B 12sep2015
B 17oct2015
;

proc sql;
create table final as 
select h.*, last.date as otherDate
from
    have as h 
    left join last as l 
        on  h.id = l.id and
            intck("DTDAY", h.date, l.date) between 0 and 1;
select * from final;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Oct 2015 17:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231400#M54571</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-23T17:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql join where date = date + 1 day</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231417#M54575</link>
      <description>&lt;P&gt;Pg, thanks, it wokrs very well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But i have one question, i work in a bank and the table i'm using has some transactions that occur in same time of the other.&lt;/P&gt;
&lt;P&gt;Just like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A Guy make a transaction in 12aug205:12:45:00&lt;/P&gt;
&lt;P&gt;And then the same guy make another transaction with same value and datetime of the first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would those lines be duplicated ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tks&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 17:58:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231417#M54575</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2015-10-23T17:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql join where date = date + 1 day</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231423#M54576</link>
      <description>&lt;P&gt;If you want to spot only the datetime pairs involving successive days then use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;intck&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"DTDAY"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; h&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;date&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; l&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;date&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; = &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but remember, this condition is true for all pairs of transactions on successive days (irrespective of the time of day). If the times must match exactly, then you should use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;l.date - h&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;date = '24:00:00't&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 18:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-where-date-date-1-day/m-p/231423#M54576</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-23T18:14:08Z</dc:date>
    </item>
  </channel>
</rss>

