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

Hi...I have a dataset that I want to select only or identify those customers as repaet customers by their ID. I can obtain a partial dataset by using the lag function but the very first record of each customer who is a repeat customer does not have "Yes" as the correct entry. Any suggestions how I might be able include the first time that  repeat customer ID is found...Thanks.

 

Have:

 

ID DATE  SALES 
1223 2016-01-23         73.55
1445 2016-01-12         88.45
1445 2016-02-11         54.70
1445 2016-03-10         66.15
1733 2016-02-08         34.50
1649 2016-02-27         66.30
1649 2016-03-13         88.20

 

 

Want:

 

ID Date  Sales  Repeat
1223 2016-01-23         73.55  
1445 2016-01-12         88.45 Yes
1445 2016-02-11         54.70 Yes
1445 2016-03-10         66.15 Yes
1733 2016-02-08         34.50  
1649 2016-02-27         66.30 Yes
1649 2016-03-13         88.20 Yes
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use the By groups?

 

data want;
set have;

BY ID;

if not first.ID then repeat='Yes';

run;

 

EDIT: Sorry, it looks like you want to identify all records that aren't unique. You can do this using First/Last, where not first.ID and last.iD

 

 

data want;
set have;

BY ID;

if not (first.ID and last.ID) then repeat='Yes';

run;

View solution in original post

1 REPLY 1
Reeza
Super User

Use the By groups?

 

data want;
set have;

BY ID;

if not first.ID then repeat='Yes';

run;

 

EDIT: Sorry, it looks like you want to identify all records that aren't unique. You can do this using First/Last, where not first.ID and last.iD

 

 

data want;
set have;

BY ID;

if not (first.ID and last.ID) then repeat='Yes';

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 648 views
  • 0 likes
  • 2 in conversation