<?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 How to: Determine if YEAR in Table 1 is within the time range [START END] in Table 2 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-if-YEAR-in-Table-1-is-within-the-time-range/m-p/897784#M354828</link>
    <description>&lt;P&gt;I currently have two tables have1 and have2, and I want to determine if the YEAR corresponding to each NAME in have2 is within the time range of have1 [START END]. If marked as 1, otherwise it is 0.&lt;/P&gt;&lt;P&gt;I hope to match two tables by CODE and obtain the table Want.&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;&lt;P&gt;Here is the data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have1;&lt;BR /&gt;input start: YYMMDD8. end: YYMMDD8. name:$1. code;&lt;BR /&gt;format start YYMMDDn8. end YYMMDDn8.;&lt;BR /&gt;datalines;&lt;BR /&gt;20050712 20060531 A 83265&lt;BR /&gt;20100624 20130812 B 79080&lt;BR /&gt;20040526 20051109 C 35423&lt;BR /&gt;20140401 20160418 D 69105&lt;BR /&gt;20170419 20180424 E 53272&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have2;&lt;BR /&gt;input year name:$1. code;&lt;BR /&gt;datalines;&lt;BR /&gt;2011 A 83265&lt;BR /&gt;2012 A 83265&lt;BR /&gt;2007 B 79080&lt;BR /&gt;2008 B 79080&lt;BR /&gt;2009 B 79080&lt;BR /&gt;2010 B 79080&lt;BR /&gt;2012 D 69105&lt;BR /&gt;2013 D 69105&lt;BR /&gt;2014 D 69105&lt;BR /&gt;2015 D 69105&lt;BR /&gt;2016 D 69105&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to obtain:&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;input year name:$1. code exist;&lt;BR /&gt;datalines;&lt;BR /&gt;2011 A 83265 0&lt;BR /&gt;2012 A 83265 0&lt;BR /&gt;2007 B 79080 0&lt;BR /&gt;2008 B 79080 0&lt;BR /&gt;2009 B 79080 0&lt;BR /&gt;2010 B 79080 1&lt;BR /&gt;2012 D 69105 0&lt;BR /&gt;2013 D 69105 0&lt;BR /&gt;2014 D 69105 1&lt;BR /&gt;2015 D 69105 1&lt;BR /&gt;2016 D 69105 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Oct 2023 11:04:50 GMT</pubDate>
    <dc:creator>Alice_SAS</dc:creator>
    <dc:date>2023-10-09T11:04:50Z</dc:date>
    <item>
      <title>How to: Determine if YEAR in Table 1 is within the time range [START END] in Table 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-if-YEAR-in-Table-1-is-within-the-time-range/m-p/897784#M354828</link>
      <description>&lt;P&gt;I currently have two tables have1 and have2, and I want to determine if the YEAR corresponding to each NAME in have2 is within the time range of have1 [START END]. If marked as 1, otherwise it is 0.&lt;/P&gt;&lt;P&gt;I hope to match two tables by CODE and obtain the table Want.&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;&lt;P&gt;Here is the data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have1;&lt;BR /&gt;input start: YYMMDD8. end: YYMMDD8. name:$1. code;&lt;BR /&gt;format start YYMMDDn8. end YYMMDDn8.;&lt;BR /&gt;datalines;&lt;BR /&gt;20050712 20060531 A 83265&lt;BR /&gt;20100624 20130812 B 79080&lt;BR /&gt;20040526 20051109 C 35423&lt;BR /&gt;20140401 20160418 D 69105&lt;BR /&gt;20170419 20180424 E 53272&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have2;&lt;BR /&gt;input year name:$1. code;&lt;BR /&gt;datalines;&lt;BR /&gt;2011 A 83265&lt;BR /&gt;2012 A 83265&lt;BR /&gt;2007 B 79080&lt;BR /&gt;2008 B 79080&lt;BR /&gt;2009 B 79080&lt;BR /&gt;2010 B 79080&lt;BR /&gt;2012 D 69105&lt;BR /&gt;2013 D 69105&lt;BR /&gt;2014 D 69105&lt;BR /&gt;2015 D 69105&lt;BR /&gt;2016 D 69105&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to obtain:&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;input year name:$1. code exist;&lt;BR /&gt;datalines;&lt;BR /&gt;2011 A 83265 0&lt;BR /&gt;2012 A 83265 0&lt;BR /&gt;2007 B 79080 0&lt;BR /&gt;2008 B 79080 0&lt;BR /&gt;2009 B 79080 0&lt;BR /&gt;2010 B 79080 1&lt;BR /&gt;2012 D 69105 0&lt;BR /&gt;2013 D 69105 0&lt;BR /&gt;2014 D 69105 1&lt;BR /&gt;2015 D 69105 1&lt;BR /&gt;2016 D 69105 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 11:04:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-if-YEAR-in-Table-1-is-within-the-time-range/m-p/897784#M354828</guid>
      <dc:creator>Alice_SAS</dc:creator>
      <dc:date>2023-10-09T11:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to: Determine if YEAR in Table 1 is within the time range [START END] in Table 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-if-YEAR-in-Table-1-is-within-the-time-range/m-p/897875#M354880</link>
      <description>&lt;P&gt;This appears to work for your example data:&lt;/P&gt;
&lt;PRE&gt;data want;
   merge have2 (in=in2)
         have1 (in=in1);
   by name code;
   exist = (year(start) le year le year(end));
   drop start end;
   if in2;
run;
&lt;/PRE&gt;
&lt;P&gt;Caution: this requires the sets to be sorted by Name and Code.&lt;/P&gt;
&lt;P&gt;IF ONLY Code is to be considered for the BY match then both sets need to be sorted by CODE.&lt;/P&gt;
&lt;P&gt;If a Name/Code in the first case, or Code in the second exists on two or more observations in both sets you will need to provide some rules as that could well mean a much more complicated situation and resolution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is a good idea when considering comparing Year or Month values against actual dates to carefully describe the rules. It may be that you get some cases where you don't expect Year=2006 to be considered in the interval 20050712 20060531 for some reason, such as less than half of 2006 is in the interval. So if&amp;nbsp; you have such rules that were not stated then you need to add them.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 20:56:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-if-YEAR-in-Table-1-is-within-the-time-range/m-p/897875#M354880</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-10-09T20:56:52Z</dc:date>
    </item>
  </channel>
</rss>

