<?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: How to :  Determine whether the year in one table is within the corresponding time range of anot in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897973#M354920</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/455700"&gt;@Alice_SAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes. But they are in different situations, especially for have1.&amp;nbsp;Each NAME and CODE corresponds to different time intervals and needs to be concatenated for judgment. The previous code cannot be implemented in this situation.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So just where is your statement of how intervals need to be concatenated and what rule(s) are applied for "judgement". I don't see anything about either action in the original problem description.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV id="bodyDisplay_30de34690cca6c" class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&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. Any part of the YEAR can be within the time range.&lt;/P&gt;
&lt;P&gt;I hope to match through the common CODE of two tables and obtain Want.&lt;/P&gt;
&lt;P&gt;Thank you for your help!&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Or in the post with the example data.&lt;/P&gt;
&lt;P&gt;If a previous solution does not work, you should post a reference to that "solution" and describe what has changed that makes it no longer suitable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Oct 2023 15:00:37 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-10-10T15:00:37Z</dc:date>
    <item>
      <title>How to :  Determine whether the year in one table is within the corresponding time range of another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897926#M354902</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. Any part of the YEAR can be within the time range.&lt;/P&gt;&lt;P&gt;I hope to match through the common CODE of two tables and obtain Want.&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 09:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897926#M354902</guid>
      <dc:creator>Alice_SAS</dc:creator>
      <dc:date>2023-10-10T09:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to :  Determine whether the year in one table is within the corresponding time range of anot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897927#M354903</link>
      <description>&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;20070531 20080531 A 83265&lt;BR /&gt;20100624 20130812 B 79080&lt;BR /&gt;20090620 20110912 B 79080&lt;BR /&gt;20040526 20051109 C 35423&lt;BR /&gt;20051109 20100831 C 35423&lt;BR /&gt;20100831 20110930 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;&lt;BR /&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;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 1&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;</description>
      <pubDate>Tue, 10 Oct 2023 09:36:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897927#M354903</guid>
      <dc:creator>Alice_SAS</dc:creator>
      <dc:date>2023-10-10T09:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to :  Determine whether the year in one table is within the corresponding time range of anot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897928#M354904</link>
      <description>&lt;P&gt;You already asked this question, and you marked an answer correct.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-Determine-if-YEAR-in-Table-2-is-within-the-time-range-of/m-p/897785#M354829" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-Determine-if-YEAR-in-Table-2-is-within-the-time-range-of/m-p/897785#M354829&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 09:53:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897928#M354904</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-10T09:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to :  Determine whether the year in one table is within the corresponding time range of anot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897932#M354905</link>
      <description>&lt;P&gt;Yes. But they are in different situations, especially for have1.&amp;nbsp;Each NAME and CODE corresponds to different time intervals and needs to be concatenated for judgment. The previous code cannot be implemented in this situation.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 10:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897932#M354905</guid>
      <dc:creator>Alice_SAS</dc:creator>
      <dc:date>2023-10-10T10:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to :  Determine whether the year in one table is within the corresponding time range of anot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897934#M354906</link>
      <description>&lt;P&gt;In the other thread, you mentioned that you have really huge data sets, and that the solution presented didn't work because you ran out of memory. Is that the case here as well?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 10:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897934#M354906</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-10T10:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to :  Determine whether the year in one table is within the corresponding time range of anot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897936#M354907</link>
      <description>&lt;P&gt;Depending on the size of have1 using a hash object could solve the problem:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.want;
   set work.have2;

   length flag more 8;

   if _n_ = 1 then do;
      if 0 then set work.have1;

      declare hash h(dataset: 'work.have1', multidata: 'yes');
      h.defineKey('name', 'code');
      h.defineData('start', 'end');
      h.defineDone();

      call missing(start, end);
   end;

   flag = 0;

   if h.find() = 0 then do;
      flag = year(start) &amp;lt;= year &amp;lt;= year(end);
      h.has_next(result: more);

      do while (more and not flag);
         rc = h.find_next();
         flag = (year(start) &amp;lt;= year &amp;lt;= year(end)) or flag;
         h.has_next(result: more);
      end;
   end;

   drop start end rc more;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Oct 2023 11:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897936#M354907</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-10-10T11:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to :  Determine whether the year in one table is within the corresponding time range of anot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897937#M354908</link>
      <description>&lt;P&gt;Yes. HAVE2 has over 60000 rows and 20 columns, while HAVE1 has 1.5 million rows and 10 columns.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 11:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897937#M354908</guid>
      <dc:creator>Alice_SAS</dc:creator>
      <dc:date>2023-10-10T11:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to :  Determine whether the year in one table is within the corresponding time range of anot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897973#M354920</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/455700"&gt;@Alice_SAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes. But they are in different situations, especially for have1.&amp;nbsp;Each NAME and CODE corresponds to different time intervals and needs to be concatenated for judgment. The previous code cannot be implemented in this situation.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So just where is your statement of how intervals need to be concatenated and what rule(s) are applied for "judgement". I don't see anything about either action in the original problem description.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV id="bodyDisplay_30de34690cca6c" class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&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. Any part of the YEAR can be within the time range.&lt;/P&gt;
&lt;P&gt;I hope to match through the common CODE of two tables and obtain Want.&lt;/P&gt;
&lt;P&gt;Thank you for your help!&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Or in the post with the example data.&lt;/P&gt;
&lt;P&gt;If a previous solution does not work, you should post a reference to that "solution" and describe what has changed that makes it no longer suitable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 15:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897973#M354920</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-10-10T15:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to :  Determine whether the year in one table is within the corresponding time range of anot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897983#M354928</link>
      <description>&lt;P&gt;What does it mean for a year to be within a time period?&lt;/P&gt;
&lt;P&gt;Do you mean that the whole year is covered by the time period?&lt;/P&gt;
&lt;PRE&gt;Period Start -------- End
Year          J---D&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;start &amp;lt;= mdy(1,1,year) and mdy(12,31,year) &amp;lt;= end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or does only part of the year need to be covered?&lt;/P&gt;
&lt;PRE&gt;Period       Start -------- End
Year       J-----D
Year                       J-----D&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;start &amp;lt;= mdy(12,31,year) and mdy(1,1,year) &amp;lt;= end&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Oct 2023 16:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/897983#M354928</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-10T16:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to :  Determine whether the year in one table is within the corresponding time range of anot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/898078#M354967</link>
      <description>&lt;P&gt;Here is a solution that uses indexed lookup - the index on the HAVE1 dataset should probably be created in the program that creates the table, not in the lookup program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
  create index idx on have1(name,code);
quit;

data want;
  set have2;
  exist=0;
  do name=name,' '; /* initialize for next read by calling with non-existing key, as keys repeat in HAVE2 */
    do until(exist);
      set have1 key=idx;
      if _iorc_ then do;
        _error_=0;
        leave;
        end;
      exist=year(start)&amp;lt;=year&amp;lt;=year(end);
      end;
      if name ne ' ' then output;
    end;
  keep year name code exist;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The good thing about this approach, when HAVE2 is the smaller table, is that we only access the records in HAVE1 that are actually relevant.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 08:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/898078#M354967</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-10-11T08:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to :  Determine whether the year in one table is within the corresponding time range of anot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/898087#M354970</link>
      <description>&lt;P&gt;Here is another possibility, which requires sorting the big HAVE1 table. We can then create a view (or a table, but a view is probably faster in this case) containing the possible years in the correct order (this is of course a very good solution if your actual data, unlike your demonstration data, is actually sorted already):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data=have1;
  by name code start;
run;

data have1_years/view=have1_years;
  do until(last.code);
    set have1; 
    by name code;
    do year=max(year+1,year(start)) to year(end);
      output;
      end;
    end;
  keep name code year;
run;
 

data want;
  merge have1_years(in=in1) have2(in=in2);
  by name code year;
  if in2;
  exist=in1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The solution can also be done extracting NAME, CODE and YEAR from HAVE1, and then sort the output data afterwards. This may be a better solution if you have many columns in HAVE1:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1_years;
  set have1; 
  do year=year(start) to year(end);
    output;
    end;
  keep name code year;
run;

Proc sort nodupkey;
  by name code year;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Oct 2023 09:01:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Determine-whether-the-year-in-one-table-is-within-the/m-p/898087#M354970</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-10-11T09:01:58Z</dc:date>
    </item>
  </channel>
</rss>

