BookmarkSubscribeRSS Feed
bw92
Calcite | Level 5

Hey Guys!

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

 

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;

 

Capture.JPG
Thank you in advance 

1 REPLY 1
PGStats
Opal | Level 21

Count the days with an array:

 

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 {&fromdt:&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;
                                           total     total
                                client_    Policy    Policy
                         Obs       id       Days      Span

                          1        1        5633      7517
PG

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1710 views
  • 0 likes
  • 2 in conversation