- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
date/colonne
Bonjour à tous,
J’ai plusieurs colonnes :
1- Colonnes « date début »
2- Colonnes « date fin »
Normalement, chaque colonne appartenant au groupe (2) devrait également appartenir au groupe (1) et vice versa. Nous devrions donc avoir le même nombre de colonnes dans les deux groupes.
Cependant, les colonnes appartenant au groupe 1 n’appartiennent pas au groupe 2 et vice versa.
Exemple : « date début 9899 » mais la colonne « date fin 9899 » n’existe pas.
L’objectif est d’avoir l’intersection de ces 2 groupes afin qu’il y ait les mêmes colonnes dans les 2 groupes.
Je m’inspire du code suivant :
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);
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: date/colonne
Here is my old school way to attack the issue
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 );
Jim
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: date/colonne
The example script you provided won't work because Word(1, col_name) will only return the first work of the string and you are comparing it to two words. So the if statement will always go to else-statement. There might be other issues, but that is at least one problem there. You can try changing Words for example to Starts With() https://www.jmp.com/support/help/en/17.0/#page/jmp/character-functions-2.shtml?os=win&source=applica.... Also make sure the cases are correct when comparing strings
-Jarmo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: date/colonne
Here is my old school way to attack the issue
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 );
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: date/colonne
Super, merci pour votre aide !