全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3971 8
2012-09-25
悬赏 20 个论坛币 已解决
问题是这样的,小弟最近在用modify处理一些大数据,其中涉及到数据集的更新,按照nkwilling版主书中的方法采取了modify语句,但在应用中发现,remove观测后的数据集大小竟然不变!

例如数据集mst有100条观测,我要删除mst数据集中的前50条观测,remove语句如下:
data mst;
  do i=1 to 100;
   output;
  end;
run;

data mst;
  modify mst;
  if i le 50 then remove;
run;

最终的mst数据集只有50条观测,但他的大小没有发生变化!!(如果原数据集很大,会更加明显)打开数据集一看,观测序号不是从1开始,而是从50开始。如果这时我再运行proc append,新增的观测序号也是从101开始,也就是说,前面50条观测被删除了,但是还占着地方!!

翻看了一下help,里面有说道remove有物理和逻辑删除之分,具体和lib的属性有关。我用的lib引擎是v9,应该执行的物理删除,但为什么删不掉呢?

望各位高人解答。

最佳答案

hikaru1066 查看完整内容

參考 http://www.nesug.org/proceedings/nesug00/cc/cc4004.pdf 其中提到"Because no observations are read in or written out during processing, for an existing dataset, the MODIFY command is the best way to add a label, rename a variable, or change a format or informat." modify比較適合作為修改資料或是變數屬性 若是要更動到整個資料檔,應該用set會比較好 希望有回答到你的問題^^
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2012-9-25 21:22:36
參考 http://www.nesug.org/proceedings/nesug00/cc/cc4004.pdf

其中提到"Because no observations are read in or written out during processing, for an existing dataset, the MODIFY command is the best way to add a label, rename a variable, or change a format or informat."

modify比較適合作為修改資料或是變數屬性
若是要更動到整個資料檔,應該用set會比較好

希望有回答到你的問題^^
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-9-26 10:37:58
没人么?自己顶一下
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-9-26 12:44:04
用你寫的程式跑了SAS是OK的...
樣本數最後剩下50個
我的SAS版本是9.2

NOTE: SAS initialization used:
      real time           1.26 seconds
      cpu time            0.96 seconds

1    data mst;
2      do i=1 to 100;
3       output;
4      end;
5    run;

NOTE: The data set WORK.MST has 100 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


6
7    data mst;
8      modify mst;
9      if i le 50 then remove;
10   run;

NOTE: There were 100 observations read from the data set WORK.MST.
NOTE: The data set WORK.MST has been updated.  There were 0 observations rewritten, 0
      observations added and 50 observations deleted.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-9-26 13:15:56
hikaru1066 发表于 2012-9-26 12:44
用你寫的程式跑了SAS是OK的...
樣本數最後剩下50個
我的SAS版本是9.2
对,样本数最后的确剩下50个,但打开数据集,观测序号是从51开始的,而非从1开始,并且数据集大小没有减少,我想问的是为什么数据集大小不变
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-9-26 13:54:40
若是把修改過後的data另存成新的檔(temp)
就可以看出觀測值僅剩50個
觀測序號也是從1開始
但就不是從修改原始檔的做法了...

data mst;
  do i=1 to 100;
   output;
  end;
run;

data mst;
  modify mst;
  if i le 50 then remove;
run;

data temp;
        set mst;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群