<?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: Merge by Date Intervals in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152729#M40163</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understand what you mean correctly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data Table1&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;
input id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;start : mmddyy10.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;: mmddyy10. location $;
format start end mmddyy10.;
cards;
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1/10/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6/30/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ap
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7/1/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ap2
;
run;
data Table2&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;
input id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;start&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;: mmddyy10. end : mmddyy10. &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;program&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $;
format start end mmddyy10.;
cards;
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1/10/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2/5/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cop1
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7/5/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;10/31/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cop2
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7/5/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cop3
;
run;
proc stdize data=table1 out=t1 missing=999999 reponly;
var end;
run;
proc stdize data=table2 out=t2 missing=999999 reponly;
var end;
run;
proc sql;
create table want as
 select&amp;nbsp; a.id,a.start,case when a.end=999999 then . else a.end end as end format=mmddyy10.,a.location ,b.program
&amp;nbsp; from t1 as a left join t2 as b on a.id=b.id and a.start le b.end and b.start le a.end;
quit;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 20 Sep 2014 12:12:14 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2014-09-20T12:12:14Z</dc:date>
    <item>
      <title>Merge by Date Intervals</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152725#M40159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello-&lt;/P&gt;&lt;P&gt;Can someone help me with data merge by date intervals? &lt;BR /&gt;I am looking to do this with the data step. &lt;BR /&gt;I am trying to merge Table1 with Table 2 to produce Final Table&lt;/P&gt;&lt;P&gt;I need the program codes (Table2) merged into location(Table1) within the effective dates at their location (Table1)&amp;nbsp; So in the example I have customer id #1 at two different locations and I want to merge the program (Table 2) as they are effective at their respective location.&amp;nbsp; Can someone help me?&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 349px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl64" height="20" width="64"&gt;Table1&lt;/TD&gt;&lt;TD class="xl64" style="border-left-color: currentColor; border-left-width: medium; border-left-style: none;" width="82"&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-left-color: currentColor; border-left-width: medium; border-left-style: none;" width="75"&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-left-color: currentColor; border-left-width: medium; border-left-style: none;" width="64"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="20" style="border-top-color: currentColor; border-top-width: medium; border-top-style: none;"&gt;id&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;start&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;end&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;location&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl64" height="20" style="border-top-color: currentColor; border-top-width: medium; border-top-style: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;1/10/2013&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;6/30/2013&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;ap&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl64" height="20" style="border-top-color: currentColor; border-top-width: medium; border-top-style: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;7/1/2013&lt;/TD&gt;&lt;TD class="xl65" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;ap2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="20"&gt;Table2&lt;/TD&gt;&lt;TD class="xl64" style="border-left-color: currentColor; border-left-width: medium; border-left-style: none;"&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-left-color: currentColor; border-left-width: medium; border-left-style: none;"&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-left-color: currentColor; border-left-width: medium; border-left-style: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="20" style="border-top-color: currentColor; border-top-width: medium; border-top-style: none;"&gt;id&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;start&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;end&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;program&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl64" height="20" style="border-top-color: currentColor; border-top-width: medium; border-top-style: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;1/10/2013&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;2/5/2013&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;cop1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl64" height="20" style="border-top-color: currentColor; border-top-width: medium; border-top-style: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;7/5/2013&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;10/31/2013&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;cop2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl64" height="20" style="border-top-color: currentColor; border-top-width: medium; border-top-style: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;7/5/2013&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;cop3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="20"&gt;Final Table&lt;/TD&gt;&lt;TD class="xl64" style="border-left-color: currentColor; border-left-width: medium; border-left-style: none;"&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-left-color: currentColor; border-left-width: medium; border-left-style: none;"&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-left-color: currentColor; border-left-width: medium; border-left-style: none;"&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-left-color: currentColor; border-left-width: medium; border-left-style: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="20" style="border-top-color: currentColor; border-top-width: medium; border-top-style: none;"&gt;id&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;start&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;end&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;location&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;program&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl64" height="20" style="border-top-color: currentColor; border-top-width: medium; border-top-style: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;1/10/2013&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;6/30/2013&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;ap&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;cop1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl64" height="20" style="border-top-color: currentColor; border-top-width: medium; border-top-style: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;7/1/2013&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;ap2&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;cop2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl64" height="20" style="border-top-color: currentColor; border-top-width: medium; border-top-style: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;7/1/2013&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;ap2&lt;/TD&gt;&lt;TD class="xl64" style="border-top-color: currentColor; border-left-color: currentColor; border-top-width: medium; border-left-width: medium; border-top-style: none; border-left-style: none;"&gt;cop3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Sep 2014 18:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152725#M40159</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2014-09-19T18:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Merge by Date Intervals</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152726#M40160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Two questions come to mind:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(1) Are START and END already stored as numerics on SAS's date scale?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(2) How would you handle a case of overlaps?&amp;nbsp; For example, what if the first observation in Table 2 had start = 1/10/2013 and end = 7/5/2013?&amp;nbsp; Would you want two locations?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The programming might be short, but the rules are important here.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Sep 2014 20:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152726#M40160</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-09-19T20:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Merge by Date Intervals</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152727#M40161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Astounding!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) I am able to convert the start and end dates to SAS dates if that will make the programming easier. &lt;/P&gt;&lt;P&gt;2) Yes- I would want the two different locations should the dates from Table 1 overlap Table 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank U&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Sep 2014 21:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152727#M40161</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2014-09-19T21:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: Merge by Date Intervals</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152728#M40162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK.&amp;nbsp; I would imagine one location would be based on the start date, and the other on the end date.&amp;nbsp; If a group spans 3 locations, that would not be captured here.&amp;nbsp; (It could, but would add complexity.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would convert Table 1 to a format.&amp;nbsp; Each range in the format would define ID + Start date through ID + End date.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data create_format;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set table1 (rename=(start=start_dt end=end_dt location=label));&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain fmtname '$locate';&lt;/P&gt;&lt;P&gt;&amp;nbsp; if end_dt=. then end_dt=9999999;&lt;/P&gt;&lt;P&gt;&amp;nbsp; start = id || ' ' || put(start_dt, 7.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end = id || ' ' || put(end_dt, 7.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc format cntlin=create_format;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then use the format in a DATA step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set table2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; location1 = put(id || ' ' || put(start, 7.), $locate.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; location 2 = put(id || ' ' || put(end, 7.), $locate.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The program is short, but not necessarily easy ... see if it makes sense to you.&amp;nbsp; Some of the renaming is necessary because PROC FORMAT expects to use START, END, and LABEL as reserved variable names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Sep 2014 21:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152728#M40162</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-09-19T21:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Merge by Date Intervals</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152729#M40163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understand what you mean correctly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data Table1&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;
input id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;start : mmddyy10.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;: mmddyy10. location $;
format start end mmddyy10.;
cards;
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1/10/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6/30/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ap
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7/1/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ap2
;
run;
data Table2&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;
input id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;start&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;: mmddyy10. end : mmddyy10. &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;program&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $;
format start end mmddyy10.;
cards;
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1/10/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2/5/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cop1
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7/5/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;10/31/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cop2
1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7/5/2013&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cop3
;
run;
proc stdize data=table1 out=t1 missing=999999 reponly;
var end;
run;
proc stdize data=table2 out=t2 missing=999999 reponly;
var end;
run;
proc sql;
create table want as
 select&amp;nbsp; a.id,a.start,case when a.end=999999 then . else a.end end as end format=mmddyy10.,a.location ,b.program
&amp;nbsp; from t1 as a left join t2 as b on a.id=b.id and a.start le b.end and b.start le a.end;
quit;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Sep 2014 12:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152729#M40163</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-09-20T12:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: Merge by Date Intervals</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152730#M40164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wondering if this can be accomplished using the Data Step and using a merge like below- where I can control the counts of the various merges?&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA YFYS YFNS NFYS;&lt;/P&gt;&lt;P&gt; MERGE table1(in=a) table2_date1(in=b); by id ; &lt;/P&gt;&lt;P&gt; IF A AND B THEN OUTPUT YFYS; &lt;/P&gt;&lt;P&gt; IF A=1 AND B=0 THEN OUTPUT YFNS;&lt;/P&gt;&lt;P&gt; IF A=0 AND B=1 THEN OUTPUT NFYS; RUN;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Sep 2014 16:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152730#M40164</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2014-09-22T16:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Merge by Date Intervals</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152731#M40165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No. I don't think so. Since you need to match an obs of Table1 to all of obs of Table2 , which means you need a Cartesian Product , this can't be done by Merge statement. However, You can use data step's Cartesian Product&amp;nbsp; to get it like : ( not as efficient as SQL's) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do i=1 to nobs;&lt;/P&gt;&lt;P&gt; set Table2 nobs=nobs point=i ;&lt;/P&gt;&lt;P&gt;...........&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Sep 2014 11:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-by-Date-Intervals/m-p/152731#M40165</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-09-23T11:49:22Z</dc:date>
    </item>
  </channel>
</rss>

