重复问题

Duplicates issue

我有重复问题。 实际上我需要的只是看到重复项,但我的 table 有很多变量,如下所示:

 a     b    c    d     e
32    ayi  dam  som   kem
32    ayi  dam  som   tws
32    ayi  dam  tsm   tws
12    mm   ds    de   ko
12    mm   tmm  to    ko

如果 'a' 'b' 'c' 和 'd' 变量相同,我会尝试保留。所以我只需要前两列。我试着这样做

 proc sort data=al nodupkey dupout=dups; 
 by a  b  c  d; 
 run; 

知道这是否有效吗?

在 SAS 9.3+ 中,您可以使用新的 nouniquekey 选项轻松完成此操作。

proc sort data=have nouniquekey out=want;
  by a b c d;
run;

这会删除任何唯一的行并留下重复项。

如果您有早期版本的 SAS,您可以在常规排序后做一些相当简单的事情。

因此,按照上面的示例排序但没有 nodupkey 后:

data want;
  set have;
  by a b c d;
  if not (first.d and last.d);
run;

根据 a b c d.

删除第一个和最后一个记录的记录

另一个选项可以是 Proc SQL,不需要预先排序:

proc sql;
create table want as
select * from have
group by a, b, c, d
having count(*)>1; /*This is to tell SAS only to keep those dups*/
quit;