あなたの問題は、end=eof
が間違った場所にあることです。
回答者のそれぞれの年齢の値の「ランク」を計算する簡単な例です。
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
ありがとう!もしあなたができるなら、もう1つ。条件の成立時にコードの2番目の部分にあるDO-LOOPが停止していないようです。何らかの理由が起こっている可能性がありますか? –
'i = 100'のときに停止しませんか? 'match = 1'のときに停止しないか?後者はそれを止めるつもりはありません、どうしてですか? – Joe