<?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 Many-to-many merge of 2 datasets with specific conditions in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Many-to-many-merge-of-2-datasets-with-specific-conditions/m-p/12519#M1688</link>
    <description>I would like to carry out a many-to-many merge of 2 datasets with specific conditions attached.  Each of the 2 datasets has a list of patients with a unique 'ID'.  Datasets can only be matched on this 'ID' variable.&lt;BR /&gt;
&lt;BR /&gt;
Dataset A (called 'dataA') has an admission date (called 'admitdate') for each patient but a patient may have multiple entries with different admission dates (ie. the same patient may appear more than once with different admit date).  &lt;BR /&gt;
&lt;BR /&gt;
Dataset B (called 'dataB') has two dates specifying an entry (called 'entrydate') and exit (called 'exitdate') time from a facility for a patient. But again, the patient may have more than one set of dates (ie. the same patient may have resided in 2 different facilities over the study period). &lt;BR /&gt;
&lt;BR /&gt;
I would like to merge 'dataA' and 'dataB' but retain only records that have a patient in 'dataB'.  &lt;BR /&gt;
&lt;BR /&gt;
I need the data to be merged by ID but only if the 'admitdate' falls within the 'entrydate' and 'exitdate' time period.&lt;BR /&gt;
&lt;BR /&gt;
I have tried the following code but do not get the results I want.&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table dataAB as &lt;BR /&gt;
select dataA.*, dataB.*&lt;BR /&gt;
from dataA, dataB&lt;BR /&gt;
where dataA.ID=dataB.ID;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Can I add a 'where' statement to this?&lt;BR /&gt;
&lt;BR /&gt;
I have also tried:&lt;BR /&gt;
&lt;BR /&gt;
data dataAB;&lt;BR /&gt;
merge dataB (in=i1) dataA (in=i2);&lt;BR /&gt;
by ID;&lt;BR /&gt;
if i1=1 then do; &lt;BR /&gt;
if i1=1 and admitdate &amp;gt;= entrydate and admitdate &amp;lt;= exitdate then output dataAB;&lt;BR /&gt;
end;&lt;BR /&gt;
run;</description>
    <pubDate>Fri, 18 Feb 2011 01:20:04 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2011-02-18T01:20:04Z</dc:date>
    <item>
      <title>Many-to-many merge of 2 datasets with specific conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Many-to-many-merge-of-2-datasets-with-specific-conditions/m-p/12519#M1688</link>
      <description>I would like to carry out a many-to-many merge of 2 datasets with specific conditions attached.  Each of the 2 datasets has a list of patients with a unique 'ID'.  Datasets can only be matched on this 'ID' variable.&lt;BR /&gt;
&lt;BR /&gt;
Dataset A (called 'dataA') has an admission date (called 'admitdate') for each patient but a patient may have multiple entries with different admission dates (ie. the same patient may appear more than once with different admit date).  &lt;BR /&gt;
&lt;BR /&gt;
Dataset B (called 'dataB') has two dates specifying an entry (called 'entrydate') and exit (called 'exitdate') time from a facility for a patient. But again, the patient may have more than one set of dates (ie. the same patient may have resided in 2 different facilities over the study period). &lt;BR /&gt;
&lt;BR /&gt;
I would like to merge 'dataA' and 'dataB' but retain only records that have a patient in 'dataB'.  &lt;BR /&gt;
&lt;BR /&gt;
I need the data to be merged by ID but only if the 'admitdate' falls within the 'entrydate' and 'exitdate' time period.&lt;BR /&gt;
&lt;BR /&gt;
I have tried the following code but do not get the results I want.&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table dataAB as &lt;BR /&gt;
select dataA.*, dataB.*&lt;BR /&gt;
from dataA, dataB&lt;BR /&gt;
where dataA.ID=dataB.ID;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Can I add a 'where' statement to this?&lt;BR /&gt;
&lt;BR /&gt;
I have also tried:&lt;BR /&gt;
&lt;BR /&gt;
data dataAB;&lt;BR /&gt;
merge dataB (in=i1) dataA (in=i2);&lt;BR /&gt;
by ID;&lt;BR /&gt;
if i1=1 then do; &lt;BR /&gt;
if i1=1 and admitdate &amp;gt;= entrydate and admitdate &amp;lt;= exitdate then output dataAB;&lt;BR /&gt;
end;&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 18 Feb 2011 01:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Many-to-many-merge-of-2-datasets-with-specific-conditions/m-p/12519#M1688</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-18T01:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: Many-to-many merge of 2 datasets with specific conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Many-to-many-merge-of-2-datasets-with-specific-conditions/m-p/12520#M1689</link>
      <description>how about this:&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table dataAB as&lt;BR /&gt;
select dataA.*, dataB.*&lt;BR /&gt;
from dataA, dataB&lt;BR /&gt;
where&lt;BR /&gt;
  dataA.ID=dataB.id&lt;BR /&gt;
  and dataA.admitdate between dataB.entrydate and dataB.exitdate;&lt;BR /&gt;
quit;</description>
      <pubDate>Fri, 18 Feb 2011 03:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Many-to-many-merge-of-2-datasets-with-specific-conditions/m-p/12520#M1689</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-02-18T03:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Many-to-many merge of 2 datasets with specific conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Many-to-many-merge-of-2-datasets-with-specific-conditions/m-p/12521#M1690</link>
      <description>Thanks DBailey.  &lt;BR /&gt;
&lt;BR /&gt;
Now I'd like to sum up the number of admits and also the length of stay for each patient.  &lt;BR /&gt;
&lt;BR /&gt;
The problem is now I have some patients with multiple 'admitdates' within a single time period (there is a different record/observation for each 'admitdate').  If I sum up the length of stay for these patients I will be counting the 'entrydate' to 'exitdate' time more than once. &lt;BR /&gt;
&lt;BR /&gt;
I am wondering if I can sum up the number of 'admitdates' for a patient within a certain time period (entrydate and exitdate) to create a single record for that patient for a particular time period.&lt;BR /&gt;
&lt;BR /&gt;
For example, I now have a patient with 3 different 'admitdate's for the time period 'entrydate' to 'exitdate'.  If each 'admitdate' is a single admission, how can I sum the number of admissions (in this case the sum would equal 3) for that patient within that period.  This patient might also have other admissions during different time period.</description>
      <pubDate>Fri, 18 Feb 2011 05:32:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Many-to-many-merge-of-2-datasets-with-specific-conditions/m-p/12521#M1690</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-18T05:32:34Z</dc:date>
    </item>
  </channel>
</rss>

