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

Hi - I just want to ask some help with regards to flagging Unique and Duplicates.

 

below is my sample data, in excel I used '=IF(I2=I1,1,0)' how do we translate that to sas? thank you.

 

CUSTOMER_KEY DidIntLoan Uniq
Customer A 0 0
Customer B 0 0
Customer B 0 1
Customer B 0 1
Customer C 0 0
Customer C 0 1
Customer D 0 0
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

or just-


data want;
 set have;
 by CUSTOMER_KEY;
 if first.CUSTOMER_KEY and last.customer_key then uniq=0;
 else uniq=not first.CUSTOMER_KEY;
run;

View solution in original post

6 REPLIES 6
Jagadishkatam
Amethyst | Level 16

please try below code

 

data have;
input CUSTOMER_KEY$10.	DidIntLoan	;
cards;
CustomerA	0
CustomerB	0
CustomerB	0
CustomerB	0
CustomerC	0
CustomerC	0
CustomerD	0
;

data want;
set have;
by CUSTOMER_KEY;
retain cnt;
if first.CUSTOMER_KEY then cnt=1;
else cnt+1;
if cnt=1 then uniq=0;
else uniq=1;
drop cnt;
run;
Thanks,
Jag
novinosrin
Tourmaline | Level 20
data have;
input CUSTOMER_KEY$10.	DidIntLoan	;
cards;
CustomerA	0
CustomerB	0
CustomerB	0
CustomerB	0
CustomerC	0
CustomerC	0
CustomerD	0
;

data want;
 set have;
 by CUSTOMER_KEY;
 if first.CUSTOMER_KEY and last.customer_key then uniq=0;
 else uniq=ifn(first.CUSTOMER_KEY,0,1);
run;
CUSTOMER_KEY DidIntLoan uniq
CustomerA 0 0
CustomerB 0 0
CustomerB 0 1
CustomerB 0 1
CustomerC 0 0
CustomerC 0 1
CustomerD 0 0
novinosrin
Tourmaline | Level 20

or just-


data want;
 set have;
 by CUSTOMER_KEY;
 if first.CUSTOMER_KEY and last.customer_key then uniq=0;
 else uniq=not first.CUSTOMER_KEY;
run;
Eugenio211
Quartz | Level 8
Thank you for the quick response.
novinosrin
Tourmaline | Level 20

Or even shorter 🙂 haha test carefully though plz-

 

data want;
 set have;
 by CUSTOMER_KEY;
 uniq=not first.CUSTOMER_KEY;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 1604 views
  • 2 likes
  • 4 in conversation