cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP 19 is here! See the new features at jmp.com/new.
  • Due to global connectivity issues impacting AWS Services, users may experience unexpected errors while attempting to authorize JMP. Please try again later or contact support@jmp.com to be notified once all issues are resolved.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
hcarr01
Level VI

Colonnes

Bonjour à tous, je dispose d’une table de données similaire à celle la :
hcarr01_0-1686040628205.png

 

La base de données est constitué de 2 groupes : 
- Les dates ( « date début... »)
- Les numéros associés à des opérations
 
Mon objectif est de supprimer les colonnes qui ne sont pas dans l’intersection des deux groupes de colonnes.
C’est à dire ici, j’aimerai supprimer automatiquement avec un script les colonnes : « Date début 952 », « 9950 »
 
Merci pour votre aide !
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Colonnes

I reworked the previous script to meet your new requirements.

Names Default To Here( 1 );

dt = Current Data Table();

keep = {};
delete = {};

colNameList = dt << get column names( string );
numericNamesOnly = colNameList;
For( i = N Items( colNameList ), i >= 1, i--,
	colNameList[i] = Uppercase( colNameList[i] );
	If( Is Missing( Num( colNameList[i] ) ) == 1,
		numericNamesOnly[i] = ""
	);
);

While( N Items( colNameList ) > 0,
	If(
		Contains( colNameList[1], Uppercase( "Date début" ) ),
			found = Contains( numericNamesOnly, Word( 3, colNameList[1] ) );
			If( found > 0,
				Insert Into( keep, colNameList[1] );
				Insert Into( keep, numericNamesOnly[found] );
				Remove From( numericNamesOnly, found, 1 );
				Remove From( numericNamesOnly, 1, 1 );
				Remove From( colNameList, found, 1 );
				Remove From( colNameList, 1, 1 );
			,
				Insert Into( delete, colNameList[1] );
				Remove From( colNameList, 1, 1 );
				Remove From( numericNamesOnly, 1, 1 );
			);,
		Is Missing( Num( colNameList[1] ) ) == 0,
			found = Contains( colNameList, Uppercase( "DATE début " ) || colNameList[1] );
			If( found > 0,
				Insert Into( keep, colNameList[1] );
				Insert Into( keep, dateDebutOnly[found] );
				Remove From( numericNamesOnly, found, 1 );
				Remove From( numericNamesOnly, 1, 1 );
				Remove From( colNameList, found, 1 );
				Remove From( colNameList, 1, 1 );
			,
				Insert Into( delete, colNameList[1] );
				Remove From( colNameList, 1, 1 );
				Remove From( numericNamesOnly, 1, 1 );
			);,
		Remove From( colNameList, 1, 1 );
		Remove From( numericNamesOnly, 1, 1 );
	)
);

dt << delete columns(delete);

It isn't pretty code, but it shows the direct way to get the job done.

Note: You have an error in your sample data table.  You have a column name "Datd début 952" that needs to be changed to "Date début 952"

Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Colonnes

I reworked the previous script to meet your new requirements.

Names Default To Here( 1 );

dt = Current Data Table();

keep = {};
delete = {};

colNameList = dt << get column names( string );
numericNamesOnly = colNameList;
For( i = N Items( colNameList ), i >= 1, i--,
	colNameList[i] = Uppercase( colNameList[i] );
	If( Is Missing( Num( colNameList[i] ) ) == 1,
		numericNamesOnly[i] = ""
	);
);

While( N Items( colNameList ) > 0,
	If(
		Contains( colNameList[1], Uppercase( "Date début" ) ),
			found = Contains( numericNamesOnly, Word( 3, colNameList[1] ) );
			If( found > 0,
				Insert Into( keep, colNameList[1] );
				Insert Into( keep, numericNamesOnly[found] );
				Remove From( numericNamesOnly, found, 1 );
				Remove From( numericNamesOnly, 1, 1 );
				Remove From( colNameList, found, 1 );
				Remove From( colNameList, 1, 1 );
			,
				Insert Into( delete, colNameList[1] );
				Remove From( colNameList, 1, 1 );
				Remove From( numericNamesOnly, 1, 1 );
			);,
		Is Missing( Num( colNameList[1] ) ) == 0,
			found = Contains( colNameList, Uppercase( "DATE début " ) || colNameList[1] );
			If( found > 0,
				Insert Into( keep, colNameList[1] );
				Insert Into( keep, dateDebutOnly[found] );
				Remove From( numericNamesOnly, found, 1 );
				Remove From( numericNamesOnly, 1, 1 );
				Remove From( colNameList, found, 1 );
				Remove From( colNameList, 1, 1 );
			,
				Insert Into( delete, colNameList[1] );
				Remove From( colNameList, 1, 1 );
				Remove From( numericNamesOnly, 1, 1 );
			);,
		Remove From( colNameList, 1, 1 );
		Remove From( numericNamesOnly, 1, 1 );
	)
);

dt << delete columns(delete);

It isn't pretty code, but it shows the direct way to get the job done.

Note: You have an error in your sample data table.  You have a column name "Datd début 952" that needs to be changed to "Date début 952"

Jim
hcarr01
Level VI

Re: Colonnes

Merci cela fonctionne ! 
J’ai essayé de reprendre votre script mais au départ je savais pas comment caractériser toutes les colonnes du deuxième groupe car il n’y a pas de termes similaires.

Recommended Articles