cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use JMP Live to centralize and share reports within groups. Webinar with Q&A April 4, 2pm ET.
Choose Language Hide Translation Bar
View Original Published Thread

Columns

hcarr01
Level VI
Hello everyone, I have a data table similar to this one:
undefined

 

The database consists of 2 groups:
- The dates ("start date...")
- Numbers associated with operations
 
My goal is to remove the columns that are not in the intersection of the two column groups.
That is to say here, I would like to automatically delete with a script the columns: "Start date 952", "9950"
 
Thanks for your help !

This post originally written in French and has been translated for your convenience. When you reply, it will also be translated back to French .

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: Columns

Thanks it works! 
I tried to use your script but initially I didn't know how to characterize all the columns of the second group because there are no similar terms.

This post originally written in French and has been translated for your convenience. When you reply, it will also be translated back to French .