<?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: Counting overlap years as a single observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720822#M223504</link>
    <description>&lt;P&gt;I just want to count the indust_code as it is; the 6191 remains 6191 but I just want to know how many of them ie. I just need the count.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
    <pubDate>Mon, 22 Feb 2021 05:10:35 GMT</pubDate>
    <dc:creator>ak2011</dc:creator>
    <dc:date>2021-02-22T05:10:35Z</dc:date>
    <item>
      <title>Displaying/printing overlap records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720730#M223498</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Can someone please help me with the code to count records of overlap years reported in two or more different jobs.&lt;/P&gt;
&lt;P&gt;Eg &amp;nbsp;with id os24, jobyrout 78 is reported in two different jobs 2 and 3. Same with Os35: jobyrout 69 is repeated for jobs 5 and 6. Same with os84: jobyrout 75 is reported for jobs 7 and 8,etc.&lt;/P&gt;
&lt;P&gt;I want a code to pull out these overlap records and count them.&lt;/P&gt;
&lt;P&gt;I really don’t have any clue to this question. I checked SAS community forum for questions &amp;nbsp;and solutions on overlap but they did not address my question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My data, code, log and results&amp;nbsp; are found below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ak.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;BR /&gt;data jobyr;&lt;BR /&gt;input id$ job jobyrin jobyrout;&lt;BR /&gt;datalines;&lt;BR /&gt;os24 1 63 73&lt;BR /&gt;os24 2 74 78&lt;BR /&gt;os24 3 78 79 &lt;BR /&gt;os24 4 80 85&lt;BR /&gt;os24 5 86 89&lt;BR /&gt;os35 4 61 64&lt;BR /&gt;os35 5 65 69&lt;BR /&gt;os35 6 69 79&lt;BR /&gt;os84 7 67 75&lt;BR /&gt;os84 8 75 81&lt;BR /&gt;os84 9 81 88&lt;BR /&gt;os94 2 14 21&lt;BR /&gt;os94 3 42 51&lt;BR /&gt;os94 4 51 68&lt;BR /&gt;os94 5 80 85&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;proc print data=jobyr;&lt;BR /&gt;title 'Table 1: Records with overlapyrs';&lt;BR /&gt; run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;72&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;73&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV class="sasSource"&gt;74 data jobyr;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;75 input id$ job jobyrin jobyrout;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;76 datalines;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogNote1_1613908921398" class="sasNote"&gt;NOTE: The data set WORK.JOBYR has 15 observations and 4 variables.&lt;/DIV&gt;
&lt;DIV id="sasLogNote2_1613908921398" class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.01 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.01 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;92 ;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;93&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;94 proc print data=jobyr;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;95 title 'Table 1: Records with overlapyrs';&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;96 run;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogNote3_1613908921398" class="sasNote"&gt;NOTE: There were 15 observations read from the data set WORK.JOBYR.&lt;/DIV&gt;
&lt;DIV id="sasLogNote4_1613908921398" class="sasNote"&gt;NOTE: PROCEDURE PRINT used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.20 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.20 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;97&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;98&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;99 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;111&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;PRE id="pre_sasLog_49" class="sasLog"&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;DIV id="IDX" class="systitleandfootercontainer"&gt;
&lt;P&gt;&lt;SPAN class="c systemtitle"&gt;Table 1: Records with overlapyrs&lt;/SPAN&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;ARTICLE aria-label="Data Set WORK.JOBYR"&gt;
&lt;TABLE class="table" aria-label="Data Set WORK.JOBYR"&gt;&lt;CAPTION aria-label="Data Set WORK.JOBYR"&gt;&amp;nbsp;&lt;/CAPTION&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;id&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;job&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;jobyrin&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;jobyrout&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="data"&gt;os24&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;63&lt;/TD&gt;
&lt;TD class="r data"&gt;73&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="data"&gt;os24&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;74&lt;/TD&gt;
&lt;TD class="r data"&gt;78&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="data"&gt;os24&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="r data"&gt;78&lt;/TD&gt;
&lt;TD class="r data"&gt;79&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="data"&gt;os24&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="r data"&gt;80&lt;/TD&gt;
&lt;TD class="r data"&gt;85&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="data"&gt;os24&lt;/TD&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;TD class="r data"&gt;86&lt;/TD&gt;
&lt;TD class="r data"&gt;89&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TD class="data"&gt;os35&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="r data"&gt;61&lt;/TD&gt;
&lt;TD class="r data"&gt;64&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;7&lt;/TH&gt;
&lt;TD class="data"&gt;os35&lt;/TD&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;TD class="r data"&gt;65&lt;/TD&gt;
&lt;TD class="r data"&gt;69&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;8&lt;/TH&gt;
&lt;TD class="data"&gt;os35&lt;/TD&gt;
&lt;TD class="r data"&gt;6&lt;/TD&gt;
&lt;TD class="r data"&gt;69&lt;/TD&gt;
&lt;TD class="r data"&gt;79&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;9&lt;/TH&gt;
&lt;TD class="data"&gt;os84&lt;/TD&gt;
&lt;TD class="r data"&gt;7&lt;/TD&gt;
&lt;TD class="r data"&gt;67&lt;/TD&gt;
&lt;TD class="r data"&gt;75&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;10&lt;/TH&gt;
&lt;TD class="data"&gt;os84&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="r data"&gt;75&lt;/TD&gt;
&lt;TD class="r data"&gt;81&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;11&lt;/TH&gt;
&lt;TD class="data"&gt;os84&lt;/TD&gt;
&lt;TD class="r data"&gt;9&lt;/TD&gt;
&lt;TD class="r data"&gt;81&lt;/TD&gt;
&lt;TD class="r data"&gt;88&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;12&lt;/TH&gt;
&lt;TD class="data"&gt;os94&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;14&lt;/TD&gt;
&lt;TD class="r data"&gt;21&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;13&lt;/TH&gt;
&lt;TD class="data"&gt;os94&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="r data"&gt;42&lt;/TD&gt;
&lt;TD class="r data"&gt;51&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;14&lt;/TH&gt;
&lt;TD class="data"&gt;os94&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="r data"&gt;51&lt;/TD&gt;
&lt;TD class="r data"&gt;68&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;15&lt;/TH&gt;
&lt;TD class="data"&gt;os94&lt;/TD&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;TD class="r data"&gt;80&lt;/TD&gt;
&lt;TD class="r data"&gt;85&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/ARTICLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Feb 2021 12:38:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720730#M223498</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2021-02-21T12:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying/printing overlap records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720731#M223499</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;Eg with id os24, jobyrout 78 is reported in two different jobs 2 and 3. Same with Os35: jobyrout 69 is repeated for jobs 5 and 6. Same with os84: jobyrout 75 is reported for jobs 7 and 8,etc.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not see this in your data. Jobyrout is 78 once in your data set.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Feb 2021 12:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720731#M223499</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-21T12:49:04Z</dc:date>
    </item>
    <item>
      <title>Counting overlap years as a single observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720737#M223501</link>
      <description>&lt;DIV&gt;
&lt;DIV class="sasSource"&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Could someone assist me with the code to count overlap year records as a single observation?&lt;/P&gt;
&lt;P&gt;For eg. I have a dataset with 9 observations, with id os24 having an overlap duration(jobyrin jobyout &amp;nbsp;for &amp;nbsp;job 2 and 3):74-78; 78-79; Same thing with os35: jobs 5 and 6 have overlap &amp;nbsp;duration 65-69;69-79.&lt;/P&gt;
&lt;P&gt;I need to have 1 single observation for the overlap duration. My expected &amp;nbsp;output (table 2) is shown below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eventually I need to have 7 records as the overlap duration was counted as 1 obs.&lt;/P&gt;
&lt;P&gt;Expected output: (Table 2)&lt;/P&gt;
&lt;P&gt;id job jobyrin jobyrout jobyrdur indust_code;&lt;BR /&gt;&lt;BR /&gt;os24 1 63 73 10 6191 &lt;BR /&gt;os24 2_3 74 79 5 6191&lt;BR /&gt;os24 4 80 85 5 6191&lt;BR /&gt;os24 5 86 89 3 6191&lt;BR /&gt;os35 4 61 64 3 6191&lt;BR /&gt;os35 5_6 65 79 14 6191&lt;BR /&gt;os84 7 67 75 8 6191&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My data, code, log and results are found below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would appreciate if you help me wit the code. I have no clue; I searched SAS online documentation, SAS forum,etc, but still I have no idea.&lt;/P&gt;
&lt;P&gt;Please help.&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;ak.&lt;/P&gt;
&lt;PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data jobyr;&lt;BR /&gt;input id$ job jobyrin jobyrout indust_code;&lt;BR /&gt;datalines;&lt;BR /&gt;os24 1 63 73 6191&lt;BR /&gt;os24 2 74 78 6191&lt;BR /&gt;os24 3 78 79 6191&lt;BR /&gt;os24 4 80 85 6191&lt;BR /&gt;os24 5 86 89 6191&lt;BR /&gt;os35 4 61 64 6191&lt;BR /&gt;os35 5 65 69 6191&lt;BR /&gt;os35 6 69 79 6191&lt;BR /&gt;os84 7 67 75 6191&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;/*proc print data=jobyr;&lt;BR /&gt;title 'Table 1: Records with overlapyrs';&lt;BR /&gt; run;*/&lt;BR /&gt;&lt;BR /&gt;/* Calculate job duration in years and count indust_code*/&lt;BR /&gt;data jobdur; set jobyr;&lt;BR /&gt;jobyrdur=jobyrout-jobyrin;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/* Count overall indust_code; both overlap and non-overlap*/&lt;BR /&gt;proc freq data=jobdur;&lt;BR /&gt;tables indust_code;&lt;BR /&gt;title 'Table 1: Indust_code count-overlap joboutyr or not'; run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* Counting indust_code: Consider overlap years per id as one duration*/&lt;BR /&gt;&lt;BR /&gt;/* No clue here: Expected output (Table 2) is shown below*/&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;72&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV class="sasSource"&gt;73 data jobyr;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;74 input id$ job jobyrin jobyrout indust_code;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;75 datalines;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogNote1_1613914920433" class="sasNote"&gt;NOTE: The data set WORK.JOBYR has 9 observations and 5 variables.&lt;/DIV&gt;
&lt;DIV id="sasLogNote2_1613914920433" class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.02 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.02 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;85 ;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;86&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;87 /*proc print data=jobyr;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;88 title 'Table 1: Records with overlapyrs';&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;89 run;*/&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;90&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;91 /* Calculate job duration in years and count indust_code*/&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;92 data jobdur; set jobyr;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;93 jobyrdur=jobyrout-jobyrin;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;94 run;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogNote3_1613914920433" class="sasNote"&gt;NOTE: There were 9 observations read from the data set WORK.JOBYR.&lt;/DIV&gt;
&lt;DIV id="sasLogNote4_1613914920433" class="sasNote"&gt;NOTE: The data set WORK.JOBDUR has 9 observations and 6 variables.&lt;/DIV&gt;
&lt;DIV id="sasLogNote5_1613914920433" class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.02 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.01 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;95&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;96 /* Count overall indust_code; both overlap and non-overlap*/&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;97 proc freq data=jobdur;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;98 tables indust_code;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;99 title 'Table 1: Indust_code count-overlap joboutyr or not'; run;&lt;/DIV&gt;
&lt;DIV id="sasLogNote6_1613914920433" class="sasNote"&gt;NOTE: There were 9 observations read from the data set WORK.JOBDUR.&lt;/DIV&gt;
&lt;DIV id="sasLogNote7_1613914920433" class="sasNote"&gt;NOTE: PROCEDURE FREQ used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.29 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.27 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;100&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;101&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;102&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;103 /* Counting indust_code: Consider overlap years per id as one duration*/&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;104&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;105 /* No clue here: Expected output (Table 2) is shown below*/&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;106&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;107 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;119&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;PRE id="pre_sasLog_55" class="sasLog"&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;DIV id="IDX" class="systitleandfootercontainer"&gt;
&lt;P&gt;&lt;SPAN class="c systemtitle"&gt;Table 1: Indust_code count-overlap joboutyr or not&lt;/SPAN&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV class="proc_title_group"&gt;
&lt;P class="c proctitle"&gt;The FREQ Procedure&lt;/P&gt;
&lt;/DIV&gt;
&lt;SECTION&gt;
&lt;ARTICLE aria-label="One-Way Frequencies"&gt;
&lt;TABLE class="table" aria-label="One-Way Frequencies"&gt;&lt;CAPTION aria-label="One-Way Frequencies"&gt;&amp;nbsp;&lt;/CAPTION&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;indust_code&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Frequency&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Percent&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Cumulative&lt;BR /&gt;Frequency&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Cumulative&lt;BR /&gt;Percent&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6191&lt;/TH&gt;
&lt;TD class="r data"&gt;9&lt;/TD&gt;
&lt;TD class="r data"&gt;100.00&lt;/TD&gt;
&lt;TD class="r data"&gt;9&lt;/TD&gt;
&lt;TD class="r data"&gt;100.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/ARTICLE&gt;
&lt;/SECTION&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Feb 2021 14:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720737#M223501</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2021-02-21T14:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying/printing overlap records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720782#M223500</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Actually, 78 appear appears twice as shown below:&lt;/P&gt;
&lt;P&gt;os24:Job 2: 74-78&lt;/P&gt;
&lt;P&gt;os24 Job3: 78-79&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Feb 2021 21:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720782#M223500</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2021-02-21T21:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Counting overlap years as a single observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720799#M223502</link>
      <description>&lt;P&gt;What about the indust_code?&amp;nbsp; Can it change during a sequence of overlapping years?&amp;nbsp; If so, what do you want to do about it?&lt;/P&gt;</description>
      <pubDate>Sun, 21 Feb 2021 23:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720799#M223502</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-02-21T23:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Counting overlap years as a single observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720821#M223503</link>
      <description>&lt;P&gt;No the indust_code does not change; it remains the same.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;ak.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 05:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720821#M223503</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2021-02-22T05:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: Counting overlap years as a single observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720822#M223504</link>
      <description>&lt;P&gt;I just want to count the indust_code as it is; the 6191 remains 6191 but I just want to know how many of them ie. I just need the count.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 05:10:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720822#M223504</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2021-02-22T05:10:35Z</dc:date>
    </item>
    <item>
      <title>Retain obs if current jobyrout equals jobyrin of next obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720829#M223509</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have done several search to obtain the right code to achieve this objective, but I have found nothing:&lt;/P&gt;
&lt;P&gt;Help needed,please:&lt;/P&gt;
&lt;P&gt;From the dataset have below, I would like to do the following:&lt;/P&gt;
&lt;P&gt;For each id job, if the jobyrout of the current observation is the same as the jobyrin of the next observation, then retain/keep that observation. Thus, for os24 jobs 2,3 jobyrout 78 (job 2) appears as jobyrin (78) for job 3. That is, 78 appears in 2 different jobs for id os24. Same logic with os35: 69 appears in jobs 5 and 6.&lt;/P&gt;
&lt;P&gt;So I want to retain these observations as shown in my expected output below.&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;ak.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My expected output is also shown below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input id$ job jobyrin jobyrout;&lt;BR /&gt;datalines;&lt;BR /&gt;os24 1 63 73 &lt;BR /&gt;os24 2 74 78 &lt;BR /&gt;os24 3 78 79 &lt;BR /&gt;os24 4 80 85 &lt;BR /&gt;os24 5 86 89 &lt;BR /&gt;os35 4 61 64 &lt;BR /&gt;os35 5 65 69 &lt;BR /&gt;os35 6 69 79 &lt;BR /&gt;os84 7 67 75 &lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Expected output&lt;BR /&gt;&lt;BR /&gt;os24 2 74 78 &lt;BR /&gt;os24 3 78 79 &lt;BR /&gt;os35 5 65 69 &lt;BR /&gt;os35 6 69 79 &lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 06:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720829#M223509</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2021-02-22T06:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: Retain obs if current jobyrout equals jobyrin of next obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720855#M223510</link>
      <description>&lt;P&gt;Hope the below helps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id$ job jobyrin jobyrout;
	jobyrout_lag = lag(jobyrout);
	datalines;
os24 1 63 73
os24 2 74 78
os24 3 78 79
os24 4 80 85
os24 5 86 89
os35 4 61 64
os35 5 65 69
os35 6 69 79
os84 7 67 75
;
run;

DATA want (drop=jobyrout_lag jobyrin_);
	_N_ ++ 1;

	IF _N_ &amp;lt;= N THEN
		DO;
			Set have POINT=_N_;
			jobyrin_ = jobyrin;
		END;
	ELSE jobyrin = .;
	Set have nobs = n;

	if jobyrout = jobyrin_ or jobyrin = jobyrout_lag then
		output;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Feb 2021 08:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720855#M223510</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-02-22T08:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Retain obs if current jobyrout equals jobyrin of next obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720858#M223511</link>
      <description>sorry got a type when pasting:&lt;BR /&gt;&lt;BR /&gt;IF _N_ &amp;lt;= N THEN&lt;BR /&gt;		DO;&lt;BR /&gt;			Set have POINT=_N_;&lt;BR /&gt;			jobyrin_ = jobyrin;&lt;BR /&gt;		END;&lt;BR /&gt;	ELSE jobyrin_ = .;  /* CHANGE HERE */&lt;BR /&gt;	Set have nobs = n;</description>
      <pubDate>Mon, 22 Feb 2021 08:44:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720858#M223511</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-02-22T08:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: Retain obs if current jobyrout equals jobyrin of next obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720872#M223512</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id$ job jobyrin jobyrout;
	datalines;
os24 1 63 73
os24 2 74 78
os24 3 78 79
os24 4 80 85
os24 5 86 89
os35 4 61 64
os35 5 65 69
os35 6 69 79
os84 7 67 75
;
run;
data want;
 merge have have(keep=id jobyrin rename=(id=_id jobyrin=_jobyrin ) firstobs=2);
 if (id=_id and jobyrout=_jobyrin) or (id=lag(id) and jobyrin=lag(jobyrout));
 drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Feb 2021 11:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720872#M223512</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-02-22T11:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Counting overlap years as a single observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720955#M223505</link>
      <description>&lt;P&gt;In your data step you need to decide whether an observation is to be skipped, due to the fact that it overlaps with the next observation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To do so, you can do a self-merge with offset, as here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;merge jobyr jobyr (firstobs=2 keep=jobyrin rename=(jobyrin=nxt_jobyrin));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which tells sas to read an observation, and also one variable (renamed) from the next observation (because it has "firstobs=2").&amp;nbsp; This will let you know whether the current obs overlaps with the next, by comparing JOBYROUT with NXT_JOBYRIN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, this doesn't protect against the end of one id overlapping with the start of the next.&amp;nbsp; To detect that condition, you can use a SET with a BY statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  set jobyr (keep=id);
  by id;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which generates dummy variables &lt;EM&gt;&lt;STRONG&gt;first.id&lt;/STRONG&gt;&lt;/EM&gt; and &lt;EM&gt;&lt;STRONG&gt;last.id&lt;/STRONG&gt;&lt;/EM&gt;, indicating whether the current obs is at the start or end of an id.&amp;nbsp; So if you are at the end of an id, you should output the current obs, even if the years overlap with the next obs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;d&lt;CODE class=" language-sas"&gt;ata want (drop=first_: nxt_: job);
  set jobyr (keep=id);
  by id;
  merge jobyr jobyr (firstobs=2 keep=jobyrin rename=(jobyrin=nxt_jobyrin));

  retain first_yrin first_job .;

  if first_yrin=. then first_yrin=jobyrin;
  if first_job=. then first_job=job;

  if last.id or nxt_jobyrin&amp;gt;jobyrout;
  jobyrin=first_yrin;
  jobs=ifc(job^=first_job,catx('_',first_job,job),cats(job));
  call missing(of first_:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then the only other task is the preserve FIRST_YRIN, which is the JOBYRIN at the start of an overlapping series.&amp;nbsp; And also similarly preserve FIRST_JOB.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The subsetting if statement&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if last.id or nxt_jobyrin&amp;gt;jobyrout;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;allows only the last record of each id, or any record that does not overlap with the upcoming record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this will accommodate an overlapping series of any length - not just two overlapping records.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 16:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/720955#M223505</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-02-22T16:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: Counting overlap years as a single observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721044#M223506</link>
      <description>&lt;P&gt;My goto paper for overlapping observations is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Starts and Stops: Processing Episode Data With Beginning and Ending Dates&lt;/P&gt;
&lt;P&gt;Mike Rhoads&lt;/P&gt;
&lt;P&gt;&lt;A href="https://urldefense.com/v3/__https:/support.sas.com/resources/papers/proceedings/proceedings/sugi29/260-29.pdf__;!!BZ50a36bapWJ!8H2kkqQWSutAvjg-9ddfWxsitq4I5VExcipHfSRoLkr7JkKTi93IH654NL8szvTw$" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi29/260-29.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that there are two separate programs in this paper.&amp;nbsp; I think you want Example 2, not Example 1.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 20:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721044#M223506</guid>
      <dc:creator>JackHamilton</dc:creator>
      <dc:date>2021-02-22T20:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Retain obs if current jobyrout equals jobyrin of next obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721208#M223513</link>
      <description>Perfect!&lt;BR /&gt;It works.&lt;BR /&gt;Thanks very much.</description>
      <pubDate>Tue, 23 Feb 2021 08:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721208#M223513</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2021-02-23T08:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Counting overlap years as a single observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721213#M223507</link>
      <description>&lt;P&gt;Thanks for your reference. I read it&amp;nbsp; but I didn't understand it. My question still remains unanswered.&lt;/P&gt;
&lt;P&gt;I still need help.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 09:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721213#M223507</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2021-02-23T09:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Counting overlap years as a single observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721216#M223508</link>
      <description>&lt;P&gt;And do not (NEVER) store years with two digits, unless you consider 2000 to come before 1999.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 09:19:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721216#M223508</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-23T09:19:23Z</dc:date>
    </item>
    <item>
      <title>Counting overlap durations as one observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721219#M223514</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I posted this question earlier, but I still have not received any response. I have read many stuff but still no clue.&lt;/P&gt;
&lt;P&gt;I would greatly appreciate the help of anyone who has a solution to this problem.&lt;/P&gt;
&lt;P&gt;My &amp;nbsp;aim is to count the icode (69) for the overlap jobyrdur as 1 observation.&lt;/P&gt;
&lt;P&gt;Jobyrdur=jobyrout-jobyrin. Icode initially is 9 but if I count the overlap jobyrdur as 1 observation final icode will be 7.&lt;/P&gt;
&lt;P&gt;There is overlap jobyrdur for os24 jobs 2 and&amp;nbsp; 3 (ie 74-78 and 78-79).&lt;/P&gt;
&lt;P&gt;Same with Os35 jobs 5 and 6 (ie. 65-69 and 69-79). I want SAS to count the icode for 74-78 and 78-79 as 1 observation. Ie. Jobyrdur2 =79-74 = 5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same Procedure with icode for 65-69 and 69-79: jobyrdur2=79-65=14.&lt;/P&gt;
&lt;P&gt;My data and expected output are shown below.&lt;/P&gt;
&lt;P&gt;Thanks in advance for your help.&lt;/P&gt;
&lt;P&gt;ak.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input id$ job jobyrin jobyrout jobyrdur icode ;&lt;BR /&gt;datalines;&lt;BR /&gt;os24 1 63 73 10 69 &lt;BR /&gt;os24 2 74 78 4 69 &lt;BR /&gt;os24 3 78 79 1 69&lt;BR /&gt;os24 4 80 85 5 69&lt;BR /&gt;os24 5 86 89 3 69&lt;BR /&gt;os35 4 61 64 3 69&lt;BR /&gt;os35 5 65 69 4 69&lt;BR /&gt;os35 6 69 79 10 69&lt;BR /&gt;os84 7 67 75 8 69&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;Expected output (data want)&lt;BR /&gt;&lt;BR /&gt;inidnew$ job jobyrin jobyrout jobyrdur2 icode;&lt;BR /&gt;os24 1 63 73 10 69 &lt;BR /&gt;os24 2_3 74 79 5 69 &lt;BR /&gt;os24 4 80 85 5 69&lt;BR /&gt;os24 5 86 89 3 69&lt;BR /&gt;os35 4 61 64 3 69&lt;BR /&gt;os35 5_6 65 79 14 69&lt;BR /&gt;os84 7 67 75 8 69&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 09:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721219#M223514</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2021-02-23T09:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: Counting overlap durations as one observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721221#M223515</link>
      <description>&lt;P&gt;I am tempted to merge this question back into the old one. It is not useful at all to repost an unanswered question.&lt;/P&gt;
&lt;P&gt;And please show what you have tried so far,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; suggested some changes to your code. &lt;/P&gt;
&lt;DIV class="sas-author-rank"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 09:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721221#M223515</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-02-23T09:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Counting overlap durations as one observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721225#M223516</link>
      <description>&lt;P&gt;Do not use 2-digit years. Remember the Y2K scare.&lt;/P&gt;
&lt;P&gt;"Those who do not learn from history are doomed to repeat it".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id$ job jobyrin jobyrout jobyrdur icode $;
datalines;
os24 1 1963 1973 10 69 
os24 2 1974 1978 4 69 
os24 3 1978 1979 1 69
os24 4 1980 1985 5 69
os24 5 1986 1989 3 69
os35 4 1961 1964 3 69
os35 5 1965 1969 4 69
os35 6 1969 1979 10 69
os84 7 1967 1975 8 69
;

data want;
merge
  have (rename=(job=_job))
  have (
    firstobs=2
    keep=id jobyrin
    rename=(id=_id jobyrin=_jobyrin)
  )
;
length job $10;
retain job __jobyrin;
if _n_ = 1 then __jobyrin = jobyrin;
job = catx("_",job,_job);
if id ne _id or jobyrout ne _jobyrin
then do;
  jobyrin = __jobyrin;
  jobyrdur = jobyrout - jobyrin;
  output;
  job = "";
  __jobyrin = _jobyrin;
end;
drop _id _job _jobyrin __jobyrin;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Feb 2021 10:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721225#M223516</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-23T10:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: Counting overlap durations as one observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721228#M223517</link>
      <description>&lt;P&gt;I merged all your posts dealing with the same issue into one thread. Please keep questions in one place in the future.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 10:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-printing-overlap-records/m-p/721228#M223517</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-23T10:31:59Z</dc:date>
    </item>
  </channel>
</rss>

