<?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 Summarize the overlap data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summarize-the-overlap-data/m-p/848064#M335292</link>
    <description>&lt;P&gt;Hi everyone, I have a question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The raw data shows that there are two people working in different companies, during their working time they also service in others company. In addition, the data shows the overlap-start time and overlap-end time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the raw data.&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;data have;
input PERSON $ 	WORK_MAIN $ START END	 SERVICE $ START END	 OVERLAP_START OVERLAP_END
;
cards;
A	AAPL 2005	2012	 TMU 2007 2012 2007 2012
A	AAPL 2005	2012	 ABC 2009 2012 2009 2012
B	TSMC 2018	2022	 TMU 2019 2022 2019 2022
B	TSMC 2018	2022	 ABC 2013 2022 2018 2022
;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="01.JPG" style="width: 944px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78105iC8E9C5E72701E301/image-size/large?v=v2&amp;amp;px=999" role="button" title="01.JPG" alt="01.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The final result I want shows below. It summarized during the time when person A worked in AAPL, he did service in one company in 2007 and in two companies in 2009.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="02.JPG" style="width: 316px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78104i7BBEE57CC1712F3D/image-size/large?v=v2&amp;amp;px=999" role="button" title="02.JPG" alt="02.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;How should I achieve it?&lt;/P&gt;
&lt;P&gt;Thank you all.&lt;/P&gt;</description>
    <pubDate>Tue, 06 Dec 2022 13:46:49 GMT</pubDate>
    <dc:creator>shawnchen0321</dc:creator>
    <dc:date>2022-12-06T13:46:49Z</dc:date>
    <item>
      <title>Summarize the overlap data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarize-the-overlap-data/m-p/848064#M335292</link>
      <description>&lt;P&gt;Hi everyone, I have a question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The raw data shows that there are two people working in different companies, during their working time they also service in others company. In addition, the data shows the overlap-start time and overlap-end time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the raw data.&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;data have;
input PERSON $ 	WORK_MAIN $ START END	 SERVICE $ START END	 OVERLAP_START OVERLAP_END
;
cards;
A	AAPL 2005	2012	 TMU 2007 2012 2007 2012
A	AAPL 2005	2012	 ABC 2009 2012 2009 2012
B	TSMC 2018	2022	 TMU 2019 2022 2019 2022
B	TSMC 2018	2022	 ABC 2013 2022 2018 2022
;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="01.JPG" style="width: 944px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78105iC8E9C5E72701E301/image-size/large?v=v2&amp;amp;px=999" role="button" title="01.JPG" alt="01.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The final result I want shows below. It summarized during the time when person A worked in AAPL, he did service in one company in 2007 and in two companies in 2009.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="02.JPG" style="width: 316px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78104i7BBEE57CC1712F3D/image-size/large?v=v2&amp;amp;px=999" role="button" title="02.JPG" alt="02.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;How should I achieve it?&lt;/P&gt;
&lt;P&gt;Thank you all.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 13:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarize-the-overlap-data/m-p/848064#M335292</guid>
      <dc:creator>shawnchen0321</dc:creator>
      <dc:date>2022-12-06T13:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize the overlap data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarize-the-overlap-data/m-p/848069#M335293</link>
      <description>&lt;P&gt;Please provide the data as working SAS data step code, as you did in your &lt;A href="https://communities.sas.com/t5/Mathematical-Optimization/Efficiency-Analysis-Run-analysis-by-region-and-year/td-p/802758" target="_self"&gt;previous thread&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 11:02:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarize-the-overlap-data/m-p/848069#M335293</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-06T11:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize the overlap data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarize-the-overlap-data/m-p/848143#M335327</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/420121"&gt;@shawnchen0321&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your data step is not working as expected, because you use the same variable names START and END for two different columns. They have to be unique.&lt;/P&gt;
&lt;P&gt;Also, there is no need to include the OVERLAP columns, as they don't supply any extra information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a two step solution, where all records are rolled out from&amp;nbsp;Main_Start to Main_End with a flag set to 1, if fthe actual year is within the Service time span, and the output is finally summarized.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Person$ Main$ Main_Start Main_End Service$ Service_Start Service_End;
;
cards;
A	AAPL 2005	2012	 TMU 2007 2012 2007 2012
A	AAPL 2005	2012	 ABC 2009 2012 2009 2012
B	TSMC 2018	2022	 TMU 2019 2022 2019 2022
B	TSMC 2018	2022	 ABC 2013 2022 2018 2022
;
run;

* Roll out;
data temp (keep=Person Year Servicekey); 
  set have;
  do Year = Main_Start to Main_End;
    if Service_Start &amp;lt;= Year &amp;lt;= Service_End then Servicekey = 1;
    else Servicekey = 0;
    output;
  end;
run;

* Summarize;
proc sql;
  create table want as
    select distinct
      Person,
      Year, 
      sum(Servicekey) as Service
    from temp
    group by 
      Person,
      Year;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Dec 2022 16:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarize-the-overlap-data/m-p/848143#M335327</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2022-12-06T16:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize the overlap data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarize-the-overlap-data/m-p/848274#M335371</link>
      <description>&lt;P&gt;It works.&lt;/P&gt;
&lt;P&gt;Big thanks for your help.&lt;/P&gt;
&lt;P&gt;Very appreciate.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 04:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarize-the-overlap-data/m-p/848274#M335371</guid>
      <dc:creator>shawnchen0321</dc:creator>
      <dc:date>2022-12-07T04:18:35Z</dc:date>
    </item>
  </channel>
</rss>

