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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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