使用 Select Where,當條件需要使用“包含”來描述需要哪些行時<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />嗨,我抓住了這個簡單的查詢:我想,我 JSL,選擇一些包含幾個不同字符串的行。 就像,一個列有一些描述符,例如'1。血樣''2。血液樣本',1.血清樣本'等。 我想在一個條件表達式中寫:
dt >> select where('樣本名稱列'包含“血液”或“血清”)。
參考良好的舊 SAS,我會寫:
數據新聞集;
設置舊集;
where(index('column','blood')>=1 or index('column','serum')>=1);
跑步;
如何在 JSL 中執行此操作?
問候波爾
回复:使用 Select Where,當條件需要使用“包含”來描述需要哪些行時嗯,更多民間傳說。腳本指南中有關於此語法的提示,但沒有確定的。謝謝女士!
回复:使用 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" )
);
回复:使用 Select Where,當條件需要使用“包含”來描述需要哪些行時我想我不久前從這個論壇上得到了“as column”語法。這有點民間傳說 - 只是說列(dt,“colname”)在這種情況下不起作用,但使用作為專欄工作了。
任何人都可以解釋為什麼作為專欄需要嗎?
回复:使用 Select Where,當條件需要使用“包含”來描述需要哪些行時嗨,答案是正確的,可以幫助我做我想做的事。 就從中學習而言,您能解釋一下為什麼會有“as 列”嗎? 是因為“包含”僅適用於列嗎? “作為列”返回正確的數據類型?
我有點難以理解這一點。
問候
波爾
回复:使用 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"));