<?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 get a tenure of a client with different start end dates? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-a-tenure-of-a-client-with-different-start-end-dates/m-p/510027#M1872</link>
    <description>&lt;P&gt;Hey Guys!&lt;/P&gt;&lt;P&gt;Just wondering how to calculate the time a client spends. As you can see, there were some gaps that this client was not holding any policy. I would like to take those gap time out of my equation. I am using&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table client_lost as 
select distinct party_id,
max(end_date) as max_end_date format date9.,
min(START_DATE) as min_start_date format date9.
group by 1
;quit;

data client_lost_2;
set client_lost;
tenure = yrdif(min_start_date,max_end_date,'Actual'); 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 399px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24608i848B24508152D5F5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;BR /&gt;Thank you in advance&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Nov 2018 19:32:45 GMT</pubDate>
    <dc:creator>bw92</dc:creator>
    <dc:date>2018-11-02T19:32:45Z</dc:date>
    <item>
      <title>How to get a tenure of a client with different start end dates?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-a-tenure-of-a-client-with-different-start-end-dates/m-p/510027#M1872</link>
      <description>&lt;P&gt;Hey Guys!&lt;/P&gt;&lt;P&gt;Just wondering how to calculate the time a client spends. As you can see, there were some gaps that this client was not holding any policy. I would like to take those gap time out of my equation. I am using&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table client_lost as 
select distinct party_id,
max(end_date) as max_end_date format date9.,
min(START_DATE) as min_start_date format date9.
group by 1
;quit;

data client_lost_2;
set client_lost;
tenure = yrdif(min_start_date,max_end_date,'Actual'); 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 399px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24608i848B24508152D5F5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;BR /&gt;Thank you in advance&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 19:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-a-tenure-of-a-client-with-different-start-end-dates/m-p/510027#M1872</guid>
      <dc:creator>bw92</dc:creator>
      <dc:date>2018-11-02T19:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a tenure of a client with different start end dates?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-a-tenure-of-a-client-with-different-start-end-dates/m-p/510113#M1884</link>
      <description>&lt;P&gt;Count the days with an array:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input client_id policy_id (start_date end_date) (:mmddyy10.);
datalines;
1 101 1/1/1990 8/1/1992
1 102 5/1/1991 11/1/1991
1 103 5/1/1993 8/1/2000
1 104 1/1/2005 8/1/2010
;

proc sql;
select min(start_date), max(end_date)
into :fromdt trimmed, :todt trimmed
from have; 
quit;

data want;
array days {&amp;amp;fromdt:&amp;amp;todt};
do until(last.client_id);
    set have; by client_id;
    do dt = start_date to end_date;
        days{dt} = 1;
        end;
    firstDt = min(firstDt, start_date);
    lastDt = max(lastDt, end_date);
    end;
totalPolicyDays = sum(of days{*});
totalPolicySpan = intck("day", firstDt, lastDt);
keep client_id totalPolicyDays totalPolicySpan;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                                           total     total
                                client_    Policy    Policy
                         Obs       id       Days      Span

                          1        1        5633      7517
&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Nov 2018 04:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-a-tenure-of-a-client-with-different-start-end-dates/m-p/510113#M1884</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-11-03T04:23:55Z</dc:date>
    </item>
  </channel>
</rss>

