列ヘッダーの検索と置換やあ、
を使用して、列ヘッダー名を正確な名前に置き換えることができます:height << Set Name( "test" );
テキストのリストがある場合は、「」に置き換えます。
どうすればそれを進めることができますか?
「名前」「時間」「性別」「身長 abc 体重」「体重 xyz」「12 身長テスト」
ケイティ 12 F 59 95 59
ルイーズ 12 F 61 123 61
最終出力:
「名前」「時間」「性別」「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?
)
);
スクリプティングRe: 列ヘッダーの検索と置換こんにちは、サムさん、
問題は、まだ置換を行っている 2 番目のループ (j) の列の直接の名前変更にあるようです。
考えられる解決策の 1 つ (以下に示す) は、ヘッダーのリスト (hl) を変更し、すべての変更が行われた後に列の名前を変更することです。
Names Default To Here( 1 );
dt = Open( "C:\Program Files\SAS\JMP\14\Samples\Data\Big Class.jmp" );
hl = dt << get column names( string );
sr = List();
sr[1] = "height"; //
sr[2] = "e"; // Order of replacement strings is critical
sr[3] = "a"; //
For( i = 1, i <= N Items( hl ), i++,
For (j = 1, j <= N Items (sr), j++,
If (contains (hl [i], sr [j]),
txt = substitute (hl [i], sr [j], "x"); // Just for clarity: the expression could be wrapped into the next
Substitute into (hl, hl [i], txt); // Hold all the changes into the hl list
)
);
Column (dt , i ) << set name (hl [i]); // Renames column only after all changes have been made
);
お役に立てば幸いです。
一番、
TS
Re: 列ヘッダーの検索と置換事前にリストを定義して、二重のネストされたループを実行しようとしました。 代用するだけ文字列置換[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], "" ) )
);
);
Re: 列ヘッダーの検索と置換こんにちは、サムさん、
スクリプトに 2 つの問題が見つかりました。
- 連結 "||" を使用しました「Or」ステートメントを表すコード (「|」である必要があります)
- 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 ""?
)
);