<?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: Merging data by name and date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/693122#M211302</link>
    <description>&lt;P&gt;If you have a many to many join, you can't use a merge statement.&amp;nbsp; A merge doesn't actually join tables together like SQL does so you end up with unexpected results if you have a many to many join.&amp;nbsp; You'll need to use proc sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;create table New6 as&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;select N.*,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; S.wanted_field1,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; S.wanted_fiedl2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;from New6 as N,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; schduling_data3 as S&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;where N.provider = S.provider&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and N.start_date between S.start_date and S.end_date;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This presupposes that you have an end date and that the provider time periods do not overlap between provider records.&amp;nbsp; If not, you will end up with duplicate rows and you will need to make a determination of which provider row is the correct one.&amp;nbsp; You may be able to do that in the proc sql step or you may want to sort your data and select it out using a data step.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Oct 2020 12:12:57 GMT</pubDate>
    <dc:creator>Groucho</dc:creator>
    <dc:date>2020-10-21T12:12:57Z</dc:date>
    <item>
      <title>Merging data by name and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/692974#M211219</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Please, I need help merging two sets of data by date and name. The first data set has the date patients were seen and the names of provider. The second data set has then date the providers started his/her shift and the names of the provider. The problem is some providers started their shift the day before the patient visited so those observations are left out of the merge. I need help including them in the merge.&lt;/P&gt;
&lt;P&gt;Below is the sas code I used.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  DATA Newdata;
   MERGE New6 (in=a) Scheduling_data3;
   BY Start_date provider; if a=1;
  RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2020 17:49:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/692974#M211219</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2020-10-20T17:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data by name and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/692978#M211223</link>
      <description>&lt;P&gt;I would simply join by provider and then check your dates after the merge has occurred.&lt;BR /&gt;&lt;BR /&gt;proc sort data=New6; by provider;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sort data=scheduling_data3; by provider;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;DATA NewData;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Merge New6(in=A) Scheduling_data3 (rename (start_date=prov_strt_dt)); by provider;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if A;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if start_date &amp;gt;= prov_strt_dt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You probably also want to put a check in for the provider end date as well.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2020 18:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/692978#M211223</guid>
      <dc:creator>Groucho</dc:creator>
      <dc:date>2020-10-20T18:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data by name and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/692988#M211229</link>
      <description>&lt;P&gt;The providers have multiple shifts so merging by provider only will not work.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2020 19:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/692988#M211229</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2020-10-20T19:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data by name and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/692995#M211235</link>
      <description>Do you have the start and end times of each shift? &lt;BR /&gt;If you could post some example data (fake data is entirely fine) that replicates your issues so we can work with a real example that would help a lot.&lt;BR /&gt;If you have the start and end times you can do this using SQL merge quite easily, if you don't it gets a bit harder as you may have to make generalizations that are not always true.</description>
      <pubDate>Tue, 20 Oct 2020 19:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/692995#M211235</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-20T19:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data by name and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/693000#M211238</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/319831"&gt;@UcheOkoro&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;The second data set has then date the providers started his/her shift and the names of the provider.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do have the END date of the shift? Perhaps a start and end time? Or can you request it?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2020 20:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/693000#M211238</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-20T20:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data by name and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/693010#M211246</link>
      <description>&lt;P&gt;Yes, I have the shift start time and date and the shift end time and date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I will need sometime to work on the fake data.&amp;nbsp;Please, how can I merge using SQL merge?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2020 20:24:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/693010#M211246</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2020-10-20T20:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data by name and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/693052#M211261</link>
      <description>&lt;P&gt;How familiar are you with SQL merges?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not, I suggest reading some papers such as this:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.lexjansen.com/pharmasug/2005/CodersCorner/cc26.pdf" target="_blank"&gt;https://www.lexjansen.com/pharmasug/2005/CodersCorner/cc26.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general though, you can merge on a range.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;from table1 as t1
left join table2 as t2
t1.id = t2.id and
on t1.eventDateTiime between t2.startDateTime and t2.endDateTime;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/319831"&gt;@UcheOkoro&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes, I have the shift start time and date and the shift end time and date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I will need sometime to work on the fake data.&amp;nbsp;Please, how can I merge using SQL merge?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 01:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/693052#M211261</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-21T01:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data by name and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/693122#M211302</link>
      <description>&lt;P&gt;If you have a many to many join, you can't use a merge statement.&amp;nbsp; A merge doesn't actually join tables together like SQL does so you end up with unexpected results if you have a many to many join.&amp;nbsp; You'll need to use proc sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;create table New6 as&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;select N.*,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; S.wanted_field1,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; S.wanted_fiedl2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;from New6 as N,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; schduling_data3 as S&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;where N.provider = S.provider&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and N.start_date between S.start_date and S.end_date;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This presupposes that you have an end date and that the provider time periods do not overlap between provider records.&amp;nbsp; If not, you will end up with duplicate rows and you will need to make a determination of which provider row is the correct one.&amp;nbsp; You may be able to do that in the proc sql step or you may want to sort your data and select it out using a data step.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 12:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/693122#M211302</guid>
      <dc:creator>Groucho</dc:creator>
      <dc:date>2020-10-21T12:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: Merging data by name and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/693277#M211357</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; proc sql;
     create table Newdata as
	 select *
         from New6, scheduling_data4 
         where New6.provider = scheduling_data4.provider
          and New6.start_date between scheduling_data4.start_date and scheduling_data4.Shift_end_date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Oct 2020 18:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-data-by-name-and-date/m-p/693277#M211357</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2020-10-21T18:33:52Z</dc:date>
    </item>
  </channel>
</rss>

