列标题搜索和替换你好,
我可以使用使用确切的名称替换列标题名称:height <<设置名称(“测试”);
如果我有一个文本列表,我想替换为“”。
我该如何进行呢?
“名称”“时间”“性别”“身高abc体重”“体重xyz”“ 12身高测试”
凯蒂12 F 59 95 59
路易丝12 F 6112361
最终输出:
“名称”“时间”“性别”“ abc”“ xyz”“ 12测试”
Names Default To Here( 1 );
dt = Open( "C:/JSL/BigClass.jmp" );
headerList = dt << get column names( string );
//:height << Set Name( "test" );
For( i = 1, i <= N Items( headerList ), i++,
If( (headerList[i] == "height" || headerList[i] == "weight"), //trying to find any column header has height or weight and replace with ""
Column( dt, colList[i] ) << set name( " " ) //above are just two examples, maybe put it in list and loop?
)
);
脚本编写回复:列标题搜索和替换你好山姆,
我在您的脚本中发现了2个问题:
- 您使用了串联“ ||”代表您的“或”语句的代码(应为“ |”)
- JMP不允许将列命名为“”。
而且,通常更方便快捷地通过数字调用列,而不是遍历列名列表
所以,这是我想出的:
Names Default To Here( 1 );
dt = Open( "C:\Program Files\SAS\JMP\14\Samples\Data\Big Class.jmp" );
headerList = dt << get column names( string );
For( i = 1, i <= N Items( headerList ), i++,
If( (headerList[i] == "height" | headerList[i] == "weight"), //Fixed the "Or" statement
Column( dt, i ) << set name(substitute (headerList [i], "e", "x")) //Used the substitute function as an example, you can replace any string with ""?
)
);
回复:列标题搜索和替换我试图提前定义列表并进行双嵌套循环。 它只替代stringReplace [3]。
headerList = dt << get column names( string );
stringReplace = List();
stringReplace[1] = "height";
stringReplace[2] = "e";
stringReplace[3] = "a";
For( i = 1, i <= N Items( headerList ), i++,
For( j = 1, j <= N Items( stringReplace ), j++,
Column( dt, i ) << set name( Substitute(headerList[i], stringReplace[j], "" ) )
);
);