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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1493 views
  • 0 likes
  • 2 in conversation