列標題搜索和替換你好,
我可以使用使用確切的名稱替換列標題名稱: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], "" ) )
);
);