2016-11-14 4 views
2

다음 코드가 있습니다. 키워드 (key_words) 목록에 대한 단락 (descr)을 테스트하려고합니다. 이 코드를 실행하면 로그가 배열의 모든 변수를 읽지 만 do 루프의 20,000 행 중 2 개만 테스트합니다 (i = 1에서 100까지 수행). 이 문제를 해결하는 방법에 대한 제안 사항이 있으십니까?SAS Do 루프가 처리중인 행을 생략합니다.

data JE.KeywordMatchTemp1; 
    set JE.JEMasterTemp end=eof; 
    if _n_ = 1 then do i = 1 by 1 until (eof); 
    set JE.KeyWords; 
    array keywords[100] $30 _temporary_; 
    keywords[i] = Key_Words; 
    end; 
    match = 0; 
    do i = 1 to 100; 
    if index(descr, keywords[i]) then match = 1; 
    end; 
    drop i; 
run; 

답변

1

end=eof의 위치가 잘못되었습니다.

이것은 각 SASHELP.CLASS 응답자의 연령 값의 '순위'를 계산하는 간단한 예입니다.

여기에 end=eof을 넣으십시오. 배열 채우기 작업을 제어하는 ​​데 사용해야하기 때문입니다. 그렇지 않으면 do i = 1 to eof; 인 루프가 발생합니다. 실제로는 eof으로 끝나지 않습니다. 실제로는 사실이 아니기 때문에 (첫 번째set 문에 정의 된대로) 실제로 종료되지 않습니다. 대신 데이터 집합의 끝 부분에 도달했기 때문에 종료됩니다. 구체적으로 원하지 않는 부분입니다.

그게 end=eof입니다. 배열 채우기 데이터 세트가 완료되면 행을 가져 오지 못하게되어 전체 데이터 단계가 종료됩니다. 정확히 2 번 반복 한 후에 데이터 단계가 종료 될 때마다 문제가 발생할 가능성을 확신 할 수 있습니다. 이는 매우 일반적인 문제입니다.

data class_ranks; 
    set sashelp.class; *This dataset you are okay iterating over until the end of the dataset and then quitting the data step, like a normal data step.; 
    array ages[19] _temporary_; 
    if _n_=1 then do; 
    do _i = 1 by 1 until (eof); *iterate until the end of the *second* set statement; 
     set sashelp.class end=eof; *see here? This eof is telling this loop when to stop. It is okay that it is not created until after the loop is.; 
     ages[_i] = age; 
    end; 
    call sortn(of ages[*]); *ordering the ages loaded by number so they are in proper order for doing the trivial rank task; 
    end; 
    age_rank = whichn(age,of ages[*]); *determine where in the list the age falls. For a real version of this task you would have to check whether this ever happens, and if not you would have to have logic to find the nearest point or whatnot.; 
run; 
+0

고맙습니다! 가능한 한 한 가지 더. 조건의 충족시 코드의 두 번째 부분에있는 DO-LOOP이 멈추지 않는 것처럼 보입니다. 무슨 일이 일어날 지 몰라요? –

+0

'i = 100' 일 때 멈추지 않습니까? 'match = 1' 일 때 멈추지 않습니까? 후자는 그것을 멈추지 않을 것입니다, 왜 그럴까요? – Joe