字符串中的列名大家好,
我正在编写一个脚本,我想使用字符串作为列名,并在公式中使用该列名,见下文:
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
//example column
dt << New Column("klaatu barada nikto", formula(3));
//suppose we don't know what exactly will be in 'a' as it is controlled by a for loop etc.
a = Concat Items( {"klaatu", "barada", "nikto"}, " " );
//can we get another column to take 'a' as an input?
dt << New Column("Gort", formula(column(a)*:Y));但是,当我使用它时,它不会将“klaatu barada nikto”视为有效列,即使我们之前创建了它。
从其他帖子中,我看到 column() 函数可用于将字符串分配给列,我以前也曾以这种方式使用过它,但在这种情况下它不起作用。 我们最终得到的是这样的:

有谁知道解决方法? 提前感谢您的任何帮助!
数据表脚本编写回复:字符串中的列名看看这个使用 Eval Insert、Eval Expr、Parse 和 Substitute 将一个表达式插入到另一个表达式中
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
//example column
dt << New Column("klaatu barada nikto", formula(3));
//suppose we don't know what exactly will be in 'a' as it is controlled by a for loop etc.
a = Concat Items( {"klaatu", "barada", "nikto"}, " " );
//can we get another column to take 'a' as an input?
Eval(EvalExpr(dt << New Column("Gort", numeric, formula(ascolumn(expr(a))*:Y))));回复:字符串中的列名极好的! 非常感谢你的帮助。