こんにちは、みんな、
いくつかの列があります。
1-「開始日」列
2-「終了日」列
通常、グループ (2) に属する各列はグループ (1) にも属する必要があり、その逆も同様です。 したがって、両方のグループに同じ数の列が必要です。
ただし、グループ 1 に属する列はグループ 2 には属さず、その逆も同様です。
例: 「開始日 9899」ですが、「終了日 9899」という列が存在しません。
目的は、これら 2 つのグループの交差部分を作成して、2 つのグループに同じ列が存在するようにすることです。
私は次のコードからインスピレーションを得ました。Names Default To Here(1);
dt = Current Data Table();
// build
aa_duree = Associative Array();
aa_nonduree = Associative Array();
For Each({col_name}, dt << Get Column Names("String"),
If(Word(1, col_name) == "date début",
aa_duree[Word(-1, col_name)] = col_name;
, !IsMissing(Regex(col_name, "")),
aa_nonduree[col_name] = 1;
,
continue()
);
);
show(aa_duree);
show(aa_nonduree);
aa_duree_copy = aa_duree;
aa_duree_copy << Intersect(aa_nonduree);
cols_to_keep = Insert(aa_duree_copy << get keys, aa_duree_copy << get values);
aa_duree_copy2 = aa_duree;
aa_nonduree_copy = aa_nonduree;
aa_duree_copy2 << remove(aa_nonduree);
aa_nonduree_copy << remove(aa_duree);
cols_to_remove = Insert(aa_nonduree_copy << get keys, aa_duree_copy2 << get values);
show(cols_to_keep, cols_to_remove); Word(1,col_name) は文字列の最初の部分のみを返し、それを 2 つの単語と比較しているため、提供したサンプル スクリプトは機能しません。 したがって、if ステートメントは常に else ステートメントに進みます。 他にも問題があるかもしれませんが、それが少なくとも 1 つの問題です。 たとえば、単語を Starts With() に変更してみてください。 https://www.jmp.com/support/help/en/17.0/#page/jmp/character-functions-2.shtml?os=win&source=application#ww2489516 。 また、文字列を比較するときに大文字と小文字が正しいことを確認してください
これが私がこの問題に取り組む昔ながらの方法です
Names Default To Here( 1 );
dt = Current Data Table();
keep = {};
delete = {};
colNameList = dt << get column names( string );
For Each( {col, i}, colNameList, colNameList[i] = Uppercase( col ) );
While( N Items( colNameList ) > 0,
If(
Contains( colNameList[1], Uppercase( "Date début" ) ),
found = Contains( colNameList, Substitute( colNameList[1], Uppercase( "début" ), "FIN" ) );
If( found > 0,
Insert Into( keep, colNameList[1] );
Insert Into( keep, colNameList[found] );
Remove From( colNameList, found, 1 );
Remove From( colNameList, 1, 1 );
,
Insert Into( delete, colNameList[1] );
Remove From( colNameList, 1, 1 )
);,
Contains( colNameList[1], Uppercase( "Date fin" ) ),
found = Contains( colNameList, Substitute( colNameList[1], "FIN", Uppercase( "début" ) ) );
If( found > 0,
Insert Into( keep, colNameList[1] );
Insert Into( keep, colNameList[found] );
Remove From( colNameList, found, 1 );
Remove From( colNameList, 1, 1 );
,
Insert Into( delete, colNameList[1] );
Remove From( colNameList, 1, 1 )
);,
Remove From( colNameList, 1, 1 )
)
);
show( keep, delete );