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!
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!
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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.