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

Hi, I would like to detect duplicate rows in my dataset below 

 

data HAVE;
infile datalines dlm="|";
input COL1 :$5. COL2 :$5. COL3 :$5.;
datalines;
CAT|DOG|ANT
ANT|CAT|DOG
HORSE|CAT|HORSE
;
run;

 

*It's in Row 1 and 2.

/*Output Duplicates*/
data WANT;
infile datalines dlm="|";
input COL1 :$5. COL2 :$5. COL3 :$5.;
datalines;
CAT|DOG|ANT
ANT|CAT|DOG
;
run;

 

I'm not sure how to do it, I was thinking of transposing, sorting, then concatenation, but it seems not efficient. Perhaps there is a better way to do it. Thank you!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You can sort inline so to speak. 

If you can have different cases (ie Ant vs ANT) they will not show up as duplicates.

 

Something like this, untested code:

 

data temp;
set have;
call sortc(col1, col2, col3);
run;

proc sort data=temp out=want nouniquekey;
by col1 col2 col3;
run;

@angeliquec wrote:

Hi, I would like to detect duplicate rows in my dataset below 

 

data HAVE;
infile datalines dlm="|";
input COL1 :$5. COL2 :$5. COL3 :$5.;
datalines;
CAT|DOG|ANT
ANT|CAT|DOG
HORSE|CAT|HORSE
;
run;

 

*It's in Row 1 and 2.

/*Output Duplicates*/
data WANT;
infile datalines dlm="|";
input COL1 :$5. COL2 :$5. COL3 :$5.;
datalines;
CAT|DOG|ANT
ANT|CAT|DOG
;
run;

 

I'm not sure how to do it, I was thinking of transposing, sorting, then concatenation, but it seems not efficient. Perhaps there is a better way to do it. Thank you!

 

 

 


 

View solution in original post

1 REPLY 1
Reeza
Super User

You can sort inline so to speak. 

If you can have different cases (ie Ant vs ANT) they will not show up as duplicates.

 

Something like this, untested code:

 

data temp;
set have;
call sortc(col1, col2, col3);
run;

proc sort data=temp out=want nouniquekey;
by col1 col2 col3;
run;

@angeliquec wrote:

Hi, I would like to detect duplicate rows in my dataset below 

 

data HAVE;
infile datalines dlm="|";
input COL1 :$5. COL2 :$5. COL3 :$5.;
datalines;
CAT|DOG|ANT
ANT|CAT|DOG
HORSE|CAT|HORSE
;
run;

 

*It's in Row 1 and 2.

/*Output Duplicates*/
data WANT;
infile datalines dlm="|";
input COL1 :$5. COL2 :$5. COL3 :$5.;
datalines;
CAT|DOG|ANT
ANT|CAT|DOG
;
run;

 

I'm not sure how to do it, I was thinking of transposing, sorting, then concatenation, but it seems not efficient. Perhaps there is a better way to do it. Thank you!

 

 

 


 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3777 views
  • 0 likes
  • 2 in conversation