使用For循环获取列脚本我有一个数据表,其中包含一些基于我手动输入的公式的新列。我想创建一个JSL脚本,允许我在另一个表中重新创建所有这些列。
以下脚本将返回我想要的单个列:
dt=current data table();
column(dt,1) << Get script;
我想使用FOR循环自动化它,但无法让它工作。任何有关如何解决这个问题的建议将不胜感激!
这是我尝试过的:
dt=current data table();
j= N cols(dt);
For( i = 1, i <=j , i++,
Column(dt,i) << Get Script;
);
Re:使用For循环获取列脚本你好 @ cjohnson6 ,
该复制所选列加载项的脚本将执行此操作 - 选择公式列,运行加载项,并将所有选定列的组合脚本复制到剪贴板,以便将其粘贴到JSL工作流中。
@julian
Re:使用For循环获取列脚本作为参考,加载项脚本的业务部分是这样的:
//collist is a list of the formula columns to be copied
For( i = 1, i <= N Items( collist ), i++,
//create a new column in the copy to data table
//substitute replaces the form in the New Column() expression with the formula from
//the source column
Eval(
Substitute(
Expr(
dt2 <<
New Column(
Column(
chosen,
Char( collist[i] )
) << get name,
formula( form )
)
),
Expr( form ),
Column( chosen, Char( collist[i] ) )
<< get formula
)
)
);
Re:使用For循环获取列脚本我刚上传了一个复制公式加载项到了文件交换 。
它将为您提供从外接程序菜单执行此操作的交互方式。

无需编写自己的脚本。
Re:使用For循环获取列脚本您可以立即获取整个数据表的脚本
dt = Current Data Table();
myScript = dt << get script;
它的缺点是它会将所有数据嵌入脚本中。 所以最简单的方法是首先删除数据,然后检索脚本
dt = Current Data Table();
dt << select all rows << delete rows;
myScript = dt << get script;
然后,编辑检索到的脚本变得很简单。
关于你的脚本,我假设你要做的是在日志中显示你的<< get script的结果,这样你就可以从那里剪切和粘贴。 JMP通常在运行脚本时显示最后一个语句的最后结果。 因此,当您只运行一列<< get script时,将显示结果。 如果要在循环中执行此操作,则需要使用“写入”,“打印”或“显示”功能将结果强制为日志。
dt = Current Data Table();
j = N Cols( dt );
For( i = 1, i <= j, i++,
Show( Column( dt, i ) << Get Script )
);
或者,如果您希望将值保留在可以以编程方式使用的结构中,则可以将结果放入列表中
dt = Current Data Table();
myList = {};
j = N Cols( dt );
For( i = 1, i <= j, i++,
myList[i] = Column( dt, i ) << Get Script
);