BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sofia2022
Fluorite | Level 6
Hi

Below is a sample of the data.

I am trying to get the number of new clients that is defined as clients who has not been seen in the 5 years preceding the first service contact during the reference period.

For example, in 2021 there were two new clients A001 and E001 (within five years).

Thank you for your help.

ClientD ContactDate
A001 01/11/2010
A001 02/11/2010
A001 04/11/2010
B001 05/06/2016
B001 07/06/2016
B001 08/06/2016
C001 08/02/2017
D001 01/03/2014
A001 03/11/2021
A001 04/11/2021
E001 02/04/2021
G001 …… (missing)
C001 02/06/2021
1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Try next code - 

 

proc sort data=have out=temp;
   by ClientID Contact_date;
run;
data want;
  set temp;
   by ClientID;
      retain first_contact;
        if first.ClientID and last.ClientID then output;
        else do;
             if first.ClientID then first_contact = Contact_Date; else
             if intnx('year',first_contact,5, 'same') < Contact_date
                then output;
run;    

 What if somone makes a contact once a year for more then 5 years. Should he be considered as a new contact ? I think that the requirement since first service should be reconsidered.

 

View solution in original post

3 REPLIES 3
Patrick
Opal | Level 21

Code like below should work.

data have;
  infile datalines truncover;
  input ClientID $ ContactDate :ddmmyy10.;
  format ContactDate date9.;
datalines;
A001 01/11/2010
A001 02/11/2010
A001 04/11/2010
B001 05/06/2010
B001 05/06/2016
B001 07/06/2016
B001 08/06/2016
C001 08/02/2017
D001 01/03/2014
A001 03/11/2021
A001 04/11/2021
E001 02/04/2021
G001 
C001 02/06/2021
;

%let ref_p_start_dt=01Jan2021;
proc sql;
  select
    ClientID,
    min(ContactDate) as ref_p_first_ContactDate format=date9.
  from have o
  where 
    ContactDate>="&ref_p_start_dt"d 
    and not exists
    (
      /* customers with contact within 5 years prior to reference period start date */
      select * 
      from have i
      where 
        intnx('year',"&ref_p_start_dt"d,-5,'s')< ContactDate < "&ref_p_start_dt"d
        and o.clientID=i.ClientID
    )
  group by
    ClientID
  ;
quit;

Patrick_0-1667694230633.png

 

Shmuel
Garnet | Level 18

Try next code - 

 

proc sort data=have out=temp;
   by ClientID Contact_date;
run;
data want;
  set temp;
   by ClientID;
      retain first_contact;
        if first.ClientID and last.ClientID then output;
        else do;
             if first.ClientID then first_contact = Contact_Date; else
             if intnx('year',first_contact,5, 'same') < Contact_date
                then output;
run;    

 What if somone makes a contact once a year for more then 5 years. Should he be considered as a new contact ? I think that the requirement since first service should be reconsidered.

 

ballardw
Super User

Your reference period is what exactly? I don't see a clear definition of any value for that.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 488 views
  • 3 likes
  • 4 in conversation