2016-11-14 9 views
2

次のコードがあります。私はキーワード(key_words)のリストの段落(descr)をテストしようとしています。このコードを実行すると、ログは配列のすべての変数を読み込みますが、doループの20,000行のうち2つだけをテストします(do i = 1〜100)。どのようにこの問題を解決するための任意の提案?SAS Do Loopが処理中の行を省略しています

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が間違った場所にあることです。

回答者のそれぞれの年齢の値の「ランク」を計算する簡単な例です。

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

ありがとう!もしあなたができるなら、もう1つ。条件の成立時にコードの2番目の部分にあるDO-LOOPが停止していないようです。何らかの理由が起こっている可能性がありますか? –

+0

'i = 100'のときに停止しませんか? 'match = 1'のときに停止しないか?後者はそれを止めるつもりはありません、どうしてですか? – Joe

関連する問題