如何删除重复的记录观察而不在 SAS 中排序? [英] How to remove duplicated recordsobservations WITHOUT sorting in SAS?

查看:15
本文介绍了如何删除重复的记录观察而不在 SAS 中排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以在排序的情况下取消重复记录?有时,我想保持原始顺序,只是想删除重复的记录.

I wonder if there is a way to unduplicate records WITHOUT sorting?Sometimes, I want to keep original order and just want to remove duplicated records.

有可能吗?

顺便说一句,以下是我所知道的关于不重复记录的内容,最终会进行排序..

BTW, below are what I know regarding unduplicating records, which does sorting in the end..

1.

proc sql;
   create table yourdata_nodupe as
   select distinct *
   From abc;
quit;

2.

proc sort data=YOURDATA nodupkey;    
    by var1 var2 var3 var4 var5;    
run;

推荐答案

您可以使用哈希对象来跟踪在您通过数据集时已看到哪些值.仅在遇到尚未观察到的键时才输出.这将按照在输入数据集中观察数据的顺序输出.

You could use a hash object to keep track of which values have been seen as you pass through the data set. Only output when you encounter a key that hasn't been observed yet. This outputs in the order the data was observed in the input data set.

这是一个使用输入数据集sashelp.cars"的示例.原始数据按 Make 的字母顺序排列,因此您可以看到输出数据集nodupes"保持相同的顺序.

Here is an example using the input data set "sashelp.cars". The original data was in alphabetical order by Make so you can see that the output data set "nodupes" maintains that same order.

data nodupes (drop=rc);;
  length Make $13.;

  declare hash found_keys();
    found_keys.definekey('Make');
    found_keys.definedone();

  do while (not done);
    set sashelp.cars end=done;
    rc=found_keys.check();
    if rc^=0 then do;      
      rc=found_keys.add(); 
      output;              
    end;
  end;
  stop;
run;

proc print data=nodupes;run;

这篇关于如何删除重复的记录观察而不在 SAS 中排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆