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

Hi,

 

 

I would like to delete a duplicate if a customer has purchased something, and then within 30 days purchases again. (Doesn't matter what kind of purchase.)

 

I have a table with non-duplicate and duplicate customer numbers (CustNo). In one column I have CustNo, in another Date.

The table is sorted by CustNo then Date. I want to make a new table where I have removed duplicates with these conditions:

 

1. CustNo=CustNo

2. The date is in within 30 days before the next date. If there is no next date for that CustNo then keep.

   

E.g:

 

CustNo  Date

123        01/11/18

123        15/11/18

123        25/11/18

123        05/12/18

123        10/01/19

456        20/11/18

 

Want outcome:

 

CustNo Date

123      05/12/18

123     10/01/19

456     20/11/18

 

I'm on version 7.1

 

Thanks 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Or  i am assuming you are perhaps after this

 

data want;
set have;
by custno;
retain d;
if first.custno and last.custno then output;
else if  first.custno then  d=date;
else if intck('days',d,date)>30 then do; d=date;output;end;
drop d;
run;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Just to make sure I am understanding this

 

05/12/18 is not removed because it is more than 30 days from the start date of 01/11/18. It doesn't matter that it is not more than 30 days since the previous purchase on 25/11/18.

--
Paige Miller
novinosrin
Tourmaline | Level 20
data have;
input CustNo  Date :ddmmyy8.;
format date ddmmyy8.;
cards;
123        01/11/18
123        15/11/18
123        25/11/18
123        05/12/18
123        10/01/19
456        20/11/18
;
data want;
set have;
by custno;
retain d;
if first.custno then do; d=date;output;end;
else if intck('days',d,date)>30 then do; d=date;output;end;
drop d;
run;

I am not sure why the 1st purchase date of custno 123 is ignored in your expected output

novinosrin
Tourmaline | Level 20

Or  i am assuming you are perhaps after this

 

data want;
set have;
by custno;
retain d;
if first.custno and last.custno then output;
else if  first.custno then  d=date;
else if intck('days',d,date)>30 then do; d=date;output;end;
drop d;
run;
PaigeMiller
Diamond | Level 26

I think the example data provided is weak and doesn't cover realistic possible examples, and so I ask for clarification from @Julia5, what do you want to happen if these are the dates for one customer?

 

01JAN18

09JAN18

14JAN18

01MAR18

05MAR18

 

Should the output include 01MAR18 and 05MAR18, because they are more than 30 days from the start? Or should the output include 01MAR18 but not 05MAR18 because 05MAR18 is less than 30 days from the previous purchase while 01MAR18 is more than 30 days from any previous purchase?

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1143 views
  • 1 like
  • 3 in conversation