且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除 SAS 中所有重复项

更新时间:2023-02-18 09:10:44

假设您正在使用带有 BY id 的 DATA 步;声明,然后添加:

Assuming you are using a DATA step with a BY id; statement, then adding:

if NOT (first.id and last.id) then delete;

应该这样做.如果这不起作用,请显示您的代码.

should do it. If that doesn't work, please show your code.

我实际上很喜欢将丢弃的记录写入单独的数据集,以便您可以跟踪在不同点丢弃的记录数.所以我会这样编码:

I'm actually a fan of writing dropped records to a separate dataset so you can track how many records were dropped at different points. So I would code this something like:

data want
     drop_dups
;
  merge a b ;
  by id ;
  if first.id and last.id then output want ;
  else output drop_dups ;
run ;