@devsas
SQL code similar to below should also work with SQL server. The basic idea is: First create a list with all duplicate key columns and then inner join this list back to your source data.
data class;
set sashelp.class;
i=1;
output;
do i=2 by 1;
if ceil(ranuni(1)*10)>5 then leave;
output;
end;
run;
proc sql;
create table want as
select l.*
from
class as l
inner join
(
select
substr(name,1,5) as name5, sex, age, count(*) as cnt
from class
group by name5, sex, age
having cnt>1
) as r
on substr(l.name,1,5)=r.name5 and l.sex=r.sex and l.age=r.age
;
quit;
... View more