BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
devon59
Calcite | Level 5

Hi,I would appreciate your help. Here's what I am trying to do. I have a dataset that tells me customerID, contact date, order date. I want to find out how many times on averagecustomers  have been contacted before they place order.

Right now, I have my code as

data  contact1; set contact;

by accountid contactdate orderdate;

if first.accountid then do;

temp=0;

end;

temp+1;

run:

This code create a column call temp that keep counting 1,2,3,4... for each accountid. However, I have this count to reset once contactdate>orderdate. How do I do that?

Any help would be very much appreciated.

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

data want(drop=order);

set have;

by ID Contactdate Orderdate;

order=lag(orderdate);

format order mmddyy10.;

if first.id or Contactdate=Order+1 then Contact_no=0;

Contact_no+1;

run;

View solution in original post

4 REPLIES 4
stat_sas
Ammonite | Level 13

Better to have a sample data. Try this

data  contact1; set contact;

by accountid contactdate orderdate;

if first.accountid or contactdate>orderdate then do;

temp=0;

end;

temp+1;

run:

devon59
Calcite | Level 5

Hi,

Thank you so much for your reply. Here's the sample data.  When I did what you suggested, anything after row 6 below has Contact#=1.  I want it to recount again 1,2,3,4...  Is that possible?

IDContact dateOrderdateContact #
111111/2/20141/6/20141
111111/3/20141/6/20142
111111/4/20141/6/20143
111111/5/20141/6/20144
111111/6/20141/6/20145
111111/7/20141/6/20141
111111/8/20141/6/20142
111111/9/20141/6/20143
111111/10/20141/6/20144
111111/11/20141/6/20145
111111/15/20141/6/20146
111111/16/20141/6/20147
111111/17/20141/6/20148
111111/18/20141/6/20149
111111/19/20141/6/201410
111111/20/20141/6/201411
111111/21/20141/6/201412
111111/22/20141/6/201413
111111/23/20141/6/201414
stat_sas
Ammonite | Level 13

data want(drop=order);

set have;

by ID Contactdate Orderdate;

order=lag(orderdate);

format order mmddyy10.;

if first.id or Contactdate=Order+1 then Contact_no=0;

Contact_no+1;

run;

devon59
Calcite | Level 5

Thank you so much!! I really appreciate it.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 4 replies
  • 979 views
  • 0 likes
  • 2 in conversation