当条件需要使用'Contain'来描述所需的行时,使用Select Where<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />嗨,我抓住这个简单的查询方法:我希望,我是JSL,选择一些包含几个不同字符串的行。像,一个columsn有一些描述符,如'1。血液样本''2。血样',1。血清样本等 我想在一个条件表达式中写:
dt >>选择where('带有样本名称的列' 包含 '血'或'血清')。
谈到好老的SAS我会写:
数据新集;
老套;
where(index('column','blood')> = 1或index('column','serum')> = 1);
跑;
如何在JSL中执行此操作?
关心Poul
Re:使用Select Where,当条件需要使用'Contain'来描述想要哪些行时嗯更民间传说。 脚本指南中有关于此语法的提示,但没有任何确定性。 谢谢MS!
Re:使用Select Where,当条件需要使用'Contain'来描述想要哪些行时下面的代码试图总结我对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,当条件需要使用'Contain'来描述想要哪些行时我想我前一段时间从这个讨论论坛得到了“as column”语法。 这有点民谣 - 只是说列(dt,“colname”) 在这种情况下不起作用,但使用作为专栏工作。
任何人都可以解释原因作为专栏需要吗?
Re:使用Select Where,当条件需要使用'Contain'来描述想要哪些行时嗨,答案是正确的,帮助我做我想做的事。从中学习,你能解释为什么'as column'存在吗?是因为'contains'只适用于列吗?'as column'返回正确的数据类型?
理解这一点我有点麻烦。
问候
波尔
Re:使用Select Where,当条件需要使用'Contain'来描述想要哪些行时你快到了。 将以下代码复制到脚本窗口并运行它:
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"));