2014-07-18 4 views
2

내 결과는 다음과 같습니다. PPD에는 누락 된 결과가 있으므로 PPD에 대한 모든 결과를 제거하고 싶습니다. 나는. ticker = 'PPD'에 누락 된 결과 (corr)가있는 레코드가 있으면 ticker = 'PPD'인 모든 레코드를 제거하고 싶습니다. SAS에서 어떻게 프로그래밍 할 수 있습니까? 나는 그러한 결핍 된 관찰을 없애고 PPD를 완전히 없애고 싶지 않습니다. 감사.SAS에서 결과가 누락 된 변수를 제거하려면 어떻게합니까?

티커 주 CORR

PPD 7-1

PPD 8

PTP 7 0.547561231

PTP (8)이 쉽게 달성된다 PROC SQL 0.183279038

답변

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; 
+0

감사합니다. proc freq는 훌륭하게 작동했습니다. – Betty

+0

누락 된 값 외에도 1, 0 또는 -1과 같은 corr도 제거 할 수 있습니까? where 명령을 또한 선택할 수있는 방법이 있습니까? 다시 한번 감사드립니다. 나는 이것을 언급한다 : 테이블 티커 * corr/missing out = ismiss (where = (missing (corr))); – Betty

+0

'where = (missing (corr) or corr in (-1,0,1))'내가 그렇게 생각해야합니다. 필요한 모든 논리 조합. – Joe

1

...

 
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 ; 

delete from 문은 소스 데이터 집합을 재귀 적으로 참조하므로 단일 SQL 단계로 수행 할 수 없습니다.

+0

데이터 세트를 반복적으로 참조하는 것에 대해 불법은 아니지만 나를 위해 잘 작동합니다 (9.3 참조). 'UNDOPOLICY = OPTIONAL' 또는'NONE'이 없으면'UPDATE'가 허용되지 않지만'UNDOPOLICY = REQUIRED '라고하더라도'DELETE'가 허용됩니다. 단지 경고 만합니다. – Joe

관련 문제