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;
출처
2016-11-14 16:16:52
Joe
고맙습니다! 가능한 한 한 가지 더. 조건의 충족시 코드의 두 번째 부분에있는 DO-LOOP이 멈추지 않는 것처럼 보입니다. 무슨 일이 일어날 지 몰라요? –
'i = 100' 일 때 멈추지 않습니까? 'match = 1' 일 때 멈추지 않습니까? 후자는 그것을 멈추지 않을 것입니다, 왜 그럴까요? – Joe