如果列不存在,则编写脚本跳过更改列大家好,
如果目标列不存在,是否有一种方法可以自动忽略一段脚本? 例如,我有如下所示的脚本,有时没有可用的“数字 C”(它是一个自动化部分,可能有也可能没有 3 个变量)。 目前,当找不到“数字 C”时,脚本会在该片段上停止;理想情况下,我想要制作一个带有多个“数字#”的脚本,如果该脚本不存在,它将自动忽略该脚本:
数据表( “1 月 5 日子集” ) ;
柱子( “柱子” ) <<数据类型(数字) ;
柱子( “柱子” ) <<造型类型(连续的) ;
柱子( “数据” ) <<数据类型(数字) ;
柱子( “数据” ) <<造型类型(连续的) ;
柱子( “数字A” ) <<数据类型(数字) ;
柱子( “数字A” ) <<造型类型(连续的) ;
柱子( “数字B” ) <<数据类型(数字) ;
柱子( “数字B” ) <<造型类型(连续的) ;
柱子( “数字C” ) <<数据类型(数字) ;
柱子( “数字C” ) <<造型类型(连续的) ;
感谢您,
乔
回复:如果列不存在,则编写脚本跳过更改列这是一个脚本,它采用您所说的尝试过的内容,并对其进行更正,以便它可以工作。我还对脚本进行了注释,以帮助理解每个语句的作用
// Set a variable "dt" to point to the data table you want to work on
// In the example you showed, it was a table called "Jan 5 Subset"
dt = Data Table("Jan 5 Subset");
// Now request to get from the data table, now referenced by the
// variable "dt" and return the list as strings
// Using the Contains function, we will check to see if a column
// named "Numerical A" is found in the returned list of column
// names. If it is, the comparison will be true and the statements
// following the "," will be executed
IF( Contains(dt << Get column names(string), "Numerical A"),
// Set the Data Type and Modeling Type for the column "Numerical A"
Column("Numerical A") <<DATA type=""></DATA>回复:如果列不存在,则编写脚本跳过更改列第二段脚本完美运行,非常感谢!回复:如果列不存在,则编写脚本跳过更改列嗨吉姆,
感谢您的快速回复。 我已经尝试过顶部功能:
dt =数据表( “1 月 5 日子集” );
如果(包含( dt < <得到柱子名称(字符串), “柱子” ),
柱子( “柱子” ) < <数据类型(数字) < <造型类型( 连续的 )
);
但是我不确定脚本中“(字符串)”的位置应该放什么?
眼下该脚本似乎在“Send Expects Scriptable Object”这一行失败。 我目前的脚本是:
如果(包含( dt <<获取列名(细绳) , “数字A” ) ,
“数字A” ) <<数据类型(数字) <<造型类型(连续的) ;
如果我在这里遗漏了一些非常明显的东西,我深表歉意,提前致谢。
回复:如果列不存在,则编写脚本跳过更改列我有几种方法可以做到这一点......
第一种是将需要限定的语句放在 IF 函数中。最正式的方法是从数据表中获取列名,然后根据是否找到该列来确定 IF 条件
dt = Data Table( "Jan 5 Subset" );
If( Contains( dt << get column names( string ), "Column" ),
Column( "Column" ) << Data Type( Numeric ) << Modeling Type( Continuous )
);
第二种方法是使用 Try 函数让 JMP 忽略它发现的任何错误
Try( Column( "Column" ) << Data Type( Numeric ) << Modeling Type( Continuous ) );
该语句可能会失败,但JMP将继续执行