多个数据表/工作流程的脚本大家好,
我对 JMP 尤其是 JSL 脚本编写还比较陌生。我正在寻找一种将现有脚本应用于所有当前打开的数据表(通过多个文件导入导入)的方法。尽管我研究了有关该主题的大量社区帖子,但我无法拼凑出一个可行的解决方案。
好的,我有以下工作 JSL 代码(注意:嵌入到工作流程中,如果相关的话):
// Specify the dataset and the suffix to search for in column headers
dt = Current Data Table();
// Define suffix of interest for replacement
targetSuffix = "TimeAbs";
// Get list of column names from the current data table
colNames = dt << Get Column Names( "string" );
// Loop through all column names and check if the target suffix is present
For( i = 1, i <= N Items( colNames ), i++,
If( Contains( colNames[i], targetSuffix ),
// If the target suffix is found, change the column header to "Date"
Column( dt, colNames[i] ) << Set Name( "Date" )
)
);工作流程的当前功能是替换当前打开的数据表中的列名称,但是该名称可能因文件而异,这就是为什么我决定仅搜索固定后缀。
我现在想扩展此脚本以应用于我当前打开的多个数据表。我已经看到过基于 For 或 For Each 循环以及表脚本的类似任务的解决方案,但正如我所说,我对 JSL 还很陌生,到目前为止还没有成功。
此外,这需要非常通用,因为文件名和列名可能会有很大差异。
最终目标是连接这些表,但可能超出了单个问题的范围。
非常感谢您的任何建议或想法
高级统计建模自动化和脚本编写基础数据分析和建模数据存取分享和交流结果回复:多个数据表/工作流的脚本您可以使用 Get Data Table List() 获取表列表,然后循环遍历该列表
Names Default To Here(1);
targetSuffix = "TimeAbs";
For Each({dt_cur}, Get Data Table List(),
colNames = dt_cur << Get Column Names("String");
For Each({colname}, colnames,
If(Contains(colname, targetSuffix),
Column(dt_cur, colname) << Set Name("Date")
)
);
);
您还可以将循环内部转换为函数或表达式
Names Default To Here(1);
change_table_name = function({dt, targetsuffix = "TimeAbs", newname = "Date"}, {Default Local},
colnames = dt << Get Column Names("String");
For Each({colname}, colnames,
If(Contains(colname, targetsuffix),
Column(dt, colname) << Set Name(newname)
)
);
);
For Each({dt_cur}, Get Data Table List(),
change_table_name(dt_cur);
);