Select Where の使用 (条件で「含む」を使用して必要な行を記述する必要がある場合)<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />こんにちは、私はこの単純なクエリをつかみます: 私は、JSL で、いくつかの異なる文字列を含むいくつかの行を選択したいと考えています。 同様に、列には '1.血液サンプル」 2.血液サンプル」、1.「血清サンプル」など。 1 つの条件式で次のように記述します。
dt >> select where('サンプル名のある列'含む「血液」または「血清」)。
古き良きSASを参照すると、次のように書くことができます:
データニュースセット;
古いセットを設定します。
where(index('column','blood')>=1 or index('column','serum')>=1);
走る;
JSLでこれを行う方法は?
よろしくポール
Re: Select Where の使用、条件で「含む」を使用して必要な行を記述する必要がある場合うーん、もっと民間伝承。スクリプト ガイドにはこの構文に関するヒントがありますが、これほど決定的なものはありません。ありがとうMS!
Re: Select Where の使用、条件で「含む」を使用して必要な行を記述する必要がある場合以下のコードは、Column() と As Column() の違いについての私の理解を要約する試みです。
//PMroz example table
dt=New Table( "Search Example",
Add Rows( 6 ),
New Column( "Sample Means",
Character,
Set Values(
{"1. blood sample", "2. blood sample", "1. serum sample",
"2. serum sample", "1. cardio sample", "2. cardio sample"}
)
)
);
// Column("X") returns a column reference.
// As Column("X") is equivalent to :X, giving access to the values of Column("X").
// Without an index, :X returns the value of the current row.
//
Row() = 3;
x = As Column( dt, "Sample Means" );
y = dt:Sample Means;
col = Column( dt, "Sample Means" );
Show( x, y, col );
// However, with an index (e.g. :X and Column("X")) both the current row
//and the column reference is bypassed; and both commands yield the same result.
x = dt:Sample Means[1];
y = Column( dt, "Sample Means" )[1];
Show( x, y );
// Hence, the below messages using As Column() Or Column()[] are equivalent.
// The empty square brackets ensures that "Select Where" loops through the value of each row.
//Without them, it would repeatedly look for a string in a column reference which would fail every time.
dt << select where(
Contains( Column( dt, "Sample Means" )[], "blood" ) |
Contains( Column( dt, "Sample Means" )[], "serum" )
);
dt << select where(
Contains( As Column( dt, "Sample Means" ), "blood" ) |
Contains( As Column( dt, "Sample Means" ), "serum" )
);
Re: Select Where の使用、条件で「含む」を使用して必要な行を記述する必要がある場合しばらく前に、このディスカッション フォーラムから「as column」構文を取得したと思います。それはちょっと民俗的です - ただ言っているだけですcolumn(dt, "colname")このコンテキストでは機能しませんでしたが、使用列として働きました。
他の誰かが理由を説明できますか列として必要ですか?
Re: Select Where の使用、条件で「含む」を使用して必要な行を記述する必要がある場合こんにちは、答えは正しく、私がやりたいことをするのに役立ちます。 そこから学ぶという意味で、「as カラム」がある理由を説明していただけますか? 「含む」が列でのみ機能するためですか? そして、「列として」は正しいデータ型を返しますか?
私はこれを理解するのに少し苦労しています。
よろしく
ポール
Re: Select Where の使用、条件で「含む」を使用して必要な行を記述する必要がある場合あなたはほとんどそこにいます。次のコードをスクリプト ウィンドウにコピーして実行します。
New Table( "Search Example",
Add Rows( 6 ),
New Column( "Sample Means",
Character,
Nominal,
Set Values(
{"1. blood sample", "2. blood sample", "1. serum sample",
"2. serum sample", "1. cardio sample", "2. cardio sample"}
)
)
);
dt = current data table();
dt << select where (contains(as column(dt, "Sample Means"), "blood") |
contains(as column(dt, "Sample Means"), "serum"));