Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
skyzvoir0001
Level III

help with code

para = {"Age","Orientation","Preference","Salary","Number","SN","Years","Service"} //some of the column names needed 

main_table_col_remain = main_tab << get column names(string);

For( i = N Items( main_table_col_remain ), i > 0, i--,
	If(!Contains( main_table_col_remain[i], ?? ) ,
		Remove From( main_table_col_remain, i )
	));
	

What do i put in the "??" part? I've been circling around this code for a while now. I want to remove column names not stored in para.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: help with code

You had the comparison backwards.  You want to take the main_table_col_remain[1] and look into the para list to see if it is there then remove it from the main_table_co_remaining list

para = {"Age", "Orientation", "Preference", "Salary", "Number", "SN", "Years", "Service"}; //some of the column names needed 

main_table_col_remain = main_tab << get column names( string );

For( i = N Items( main_table_col_remain ), i > 0, i--,
	If( Contains( Para, main_table_col_remain[i] ),
		Remove From( main_table_col_remain, i, 1 )
	)
);
Jim

View solution in original post

3 REPLIES 3
Highlighted
txnelson
Super User

Re: help with code

You had the comparison backwards.  You want to take the main_table_col_remain[1] and look into the para list to see if it is there then remove it from the main_table_co_remaining list

para = {"Age", "Orientation", "Preference", "Salary", "Number", "SN", "Years", "Service"}; //some of the column names needed 

main_table_col_remain = main_tab << get column names( string );

For( i = N Items( main_table_col_remain ), i > 0, i--,
	If( Contains( Para, main_table_col_remain[i] ),
		Remove From( main_table_col_remain, i, 1 )
	)
);
Jim

View solution in original post

Highlighted
skyzvoir0001
Level III

Re: help with code

follow up question, how do i tweak this code so that it does not split it individually? 

for(i=1, i<=n, i++,
	if((contains item(Para[i], main_table_col_remain) == 1),
		param = main_table_col_remain[i];
		tempdt =eval(parse( " combined_tab << Split(
		Split By(:Source_Table),
		Split(:Name(\!"" ||param|| "\!")),
		Remaining Columns(Drop All),
		Sort by Column Property	
		)"
		))));
		
Highlighted
txnelson
Super User

Re: help with code

If I am correctly reading what you want to do, all you need to do, is to place all of the main_table_col_remain columns into the Split definition at the same time.  Here is a simple example of splitting both Height and Weight by the Sex column in the Big Class sample data table

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );
dt << Split( Split By( :sex ), Split( :height, :weight ), Remaining Columns( Drop All ), Sort by Column Property );

With the complex names you have in your data table, I would have a tendency to add :Name() to each element in your main_table_col_remain and in your case, turn the list into a string

myString = ":Name( \!"" || char(main_table_col_remain[1]) || "\!" )";
For( I = 2, I<= N Items( main_table_col_remain ), i++,
     myString = myString || ", :Name( \!"" || char(main_table_col_remain[i]) || "\!" )" ;
);

then you can add the entire list to the split

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

main_table_col_remain = dt << get column names( string, continuous );

myString = ":Name( \!"" || Char( main_table_col_remain[1] ) || "\!" )";
For( I = 2, I <= N Items( main_table_col_remain ), i++,
	myString = myString || ", :Name( \!"" || Char( main_table_col_remain[i] ) || "\!" )"
);

Eval(
	Parse(
		"
dtSplit = dt << Split(
	Split By( :sex ),
	Split( " || myString ||
		" ),
	Remaining Columns( Drop All ),
	Sort by Column Property
);"
	)
);
Jim
Article Labels

    There are no labels assigned to this post.