Hallo an alle,
Ich habe mehrere Spalten:
1-Spalten „Startdatum“.
2- Spalten „Enddatum“.
Normalerweise sollte jede Spalte, die zur Gruppe (2) gehört, auch zur Gruppe (1) gehören und umgekehrt. Wir sollten also in beiden Gruppen die gleiche Anzahl von Spalten haben.
Allerdings gehören Spalten, die zu Gruppe 1 gehören, nicht zu Gruppe 2 und umgekehrt.
Beispiel : „Startdatum 9899“, aber die Spalte „Enddatum 9899“ existiert nicht.
Das Ziel besteht darin, die Schnittmenge dieser beiden Gruppen zu ermitteln, sodass in den beiden Gruppen die gleichen Spalten vorhanden sind.
Mich inspiriert folgender Code: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); Das von Ihnen bereitgestellte Beispielskript funktioniert nicht, da Word(1, col_name) nur das erste Werk der Zeichenfolge zurückgibt und Sie es mit zwei Wörtern vergleichen. Die if-Anweisung wird also immer zur else-Anweisung weitergeleitet. Es könnte noch andere Probleme geben, aber das ist zumindest ein Problem. Sie können beispielsweise versuchen, Wörter in „Beginnt mit()“ zu ändern. https://www.jmp.com/support/help/en/17.0/#page/jmp/character-functions-2.shtml?os=win&source=application#ww2489516 . Stellen Sie beim Vergleich von Zeichenfolgen außerdem sicher, dass die Groß- und Kleinschreibung korrekt ist
Hier ist meine altmodische Art, das Problem anzugehen
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 );Großartig, danke für deine Hilfe!