如何消除SAS中缺少结果的变量?

时间:2014-07-18 13:17:53

标签: sas

以下是我的结果。由于PPD缺少结果,我想消除PPD的所有结果。即我想删除所有记录,其中ticker =' PPD'如果有任何记录,其中ticker =' PPD'有一个缺失的结果(corr)。 我如何在SAS中编程?我不想只是消除那个缺失的观察结果,而是完全消除PPD。感谢。

Ticker Day Corr

PPD 7 -1

PPD 8

PTP 7 0.547561231

PTP 8 0.183279038

2 个答案:

答案 0 :(得分:2)

有很多方法可以做到这一点,最有效的方法取决于您的数据。如果您没有太多数据,那么我会使用最符合您的知识和其他习惯的方法。

*SQL delete;
proc sql;
  delete from have H where exists (
     select 1 from have V where H.ticker=V.ticker and V.corr is null);
quit;

*FREQ for missing (or means or whatever) then delete from that;
*Requires have to be sorted.;
proc freq data=have;
 tables ticker*corr/missing out=ismiss(where=(missing(corr)));
run;

data want;
 merge have(in=_h) ismiss(in=_m);
 by ticker;
 if _h and not _m;
run;


*double DoW.  Requires either dataset is sorted by ticker,;
*or requires it to be organized by ticker (but tickers can be not alphabetically sorted); *and use norsorted on by statement;
data want;
  do _n_=1 by 1 until (last.ticker);
    set have;
    by ticker;
    if missing(corr) then _miss=1;
  end;
  do _n_=1 by 1 until (last.ticker);
    set have;
    by ticker;
    if _miss ne 1 then output;
  end;
run;

答案 1 :(得分:1)

这可以在PROC SQL ...

中轻松完成
proc sql ;
  create table to_delete as
  select distinct ticker
  from mydata
  where missing(corr) ;

  delete from mydata
  where ticker in(select ticker from to_delete) ;
quit ;

不幸的是,它不能在单个SQL步骤中完成,因为delete from语句将递归引用源数据集。