来自字符串的列名称大家好,
我正在编写一个脚本,我想使用字符串作为列名称,并在公式中使用该列名称,请参见下文:
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()函数可用于将字符串分配给列,并且我以前以这种方式使用过它,但在这种情况下它不起作用。 我们最终得到的是这样的:

有谁知道这个问题的解决方法? 感谢您提前提供任何帮助!
高级统计建模自动化和脚本编写实验设计回复:字符串中的列名如果我正确理解你想要什么,你可以尝试添加 Name Expr
Names Default To Here(1);
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"}, " " );
Eval(EvalExpr(dt << New Column("Gort", numeric, formula(Expr(Name Expr(As Column(a)))*:Y))));

回复:字符串中的列名雅尔莫,
我在一个脚本中使用了相同的方法,但遇到了一个问题:新列中的公式将具有“a”列,如下所示:
Formula(As Column("klaatu barada nikto")*:Y)这意味着如果该列的名称发生更改(在我的情况下发生更改),则该公式将变得无效。 我需要以某种方式引用它而不是作为列(“名称”)但作为:姓名- 有办法做到这一点吗?
</CODE><CODE class=" language-jsl">
</CODE></P><P> </P><P> </P></LINGO-BODY><LINGO-SUB id="lingo-sub-393062" slang="en-US" mode="NONE">回复:字符串中的列名</LINGO-SUB><LINGO-BODY id="lingo-body-393062" slang="en-US" mode="NONE"><P>极好的! 非常感谢你的帮助。</P></LINGO-BODY><LINGO-SUB id="lingo-sub-393057" slang="en-US" mode="NONE">回复:字符串中的列名</LINGO-SUB><LINGO-BODY id="lingo-body-393057" slang="en-US" mode="NONE"><P>看看这个<A href="https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998" target="_blank">使用 Eval Insert、Eval Expr、Parse 和 Substitute 将一个表达式插入另一个表达式</A></P><P> </P><PRE><CODE class=" language-jsl">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))));