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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1670 views
  • 2 likes
  • 4 in conversation