<?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 Merging two datasets in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Merging-two-datasets/m-p/544684#M16744</link>
    <description>&lt;P&gt;Dear SAS Users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to merge two datasets. In particular,&amp;nbsp; I need to merge "return" data to "link" such that the "date" in "return" is between "&lt;FONT&gt;LINKDT" and "LINKENDDT" in "link" data. For this I use the code below:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table comp2 as
select a.*, b.fyrc, b.gvkey
from return as a, link as b
where a.permno=b.lpermno and b.linkprim in ('P', 'C') and
b.LINKTYPE in ('LU', 'LC') and
a.date&amp;gt;= b.LINKDT and (a.date &amp;lt;= b.LINKENDDT or missing(b.LINKENDDT))
order by gvkey, date;
quit;&lt;/PRE&gt;&lt;P&gt;The result that I get is that I have a merge for "gvkey" = &lt;SPAN&gt;7701. Even though in the "link" it has "LINKDT" and "LINKENDDT " as&amp;nbsp;31-Jan-67 29-Dec-67&amp;nbsp; and 01-Jan-68 03-Jan-67. Basically, I should not be merged. Can you, please help me to resolve this issue? Why do this firm has a merge? I attach two datasets that I use (a sample)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Mar 2019 19:03:26 GMT</pubDate>
    <dc:creator>Alberto_Alvarez</dc:creator>
    <dc:date>2019-03-20T19:03:26Z</dc:date>
    <item>
      <title>Merging two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Merging-two-datasets/m-p/544684#M16744</link>
      <description>&lt;P&gt;Dear SAS Users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to merge two datasets. In particular,&amp;nbsp; I need to merge "return" data to "link" such that the "date" in "return" is between "&lt;FONT&gt;LINKDT" and "LINKENDDT" in "link" data. For this I use the code below:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table comp2 as
select a.*, b.fyrc, b.gvkey
from return as a, link as b
where a.permno=b.lpermno and b.linkprim in ('P', 'C') and
b.LINKTYPE in ('LU', 'LC') and
a.date&amp;gt;= b.LINKDT and (a.date &amp;lt;= b.LINKENDDT or missing(b.LINKENDDT))
order by gvkey, date;
quit;&lt;/PRE&gt;&lt;P&gt;The result that I get is that I have a merge for "gvkey" = &lt;SPAN&gt;7701. Even though in the "link" it has "LINKDT" and "LINKENDDT " as&amp;nbsp;31-Jan-67 29-Dec-67&amp;nbsp; and 01-Jan-68 03-Jan-67. Basically, I should not be merged. Can you, please help me to resolve this issue? Why do this firm has a merge? I attach two datasets that I use (a sample)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 19:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Merging-two-datasets/m-p/544684#M16744</guid>
      <dc:creator>Alberto_Alvarez</dc:creator>
      <dc:date>2019-03-20T19:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Merging-two-datasets/m-p/544722#M16746</link>
      <description>&lt;P&gt;Problem: Your Linkenddt is a datetime variable and Linkdt is a date. So the two values do not use the same units of measure. Dates are number of days since 01JAN1960 and datetimes are numbers of seconds from 01Jan1960:00:00:00.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just opening your data set link it shows linkenddt values like : 29DEC67:00:00:00 so your post didn't pay any attention to the format of the actual values in the set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, you might want to watch this behavior when reading from popular Microsoft data sources. Many of them include a no hours, minutes or seconds time portion because the software is defaulting to date time storage and formats even though dates are intended. When all of the values for time are 00:00:00 you might consider trimming the values permanently using the datepart function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To compare dates with datetimes you likely want to use&lt;/P&gt;
&lt;P&gt;a.date &amp;lt;= datepart (b.LINKENDDT)&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 22:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Merging-two-datasets/m-p/544722#M16746</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-20T22:46:25Z</dc:date>
    </item>
  </channel>
</rss>

