cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
kachveder
Level III

From a Selection of Column Names, how do I modify the resulting column name list

Hi there, 

 

Maybe you can help me figure out what I am doing wrong here.

 

I have the following toy data table:

 

kachveder_2-1631473405906.png

 

 

I have been having some trouble with refining a list of character column names becoming from the following script. 

 

//get unique column names
cols = Current Data Table() << getColumnNames(Character);
//del columns I don't want
DELCOLS = {"Column 5", "Column 6"};
unique_col_names = Associative Array(cols) << Remove(Associative Array(DELCOLS)) << get keys;

//make a pop-up window
nw = New Window( "Set a Value",
<<Modal,
Text Box("Set the character variable:"), 
variablebox1_col_name = Radio Box( unique_col_names ),
H List Box(
//get all saved variable values when the user 
//selects the OK button from the menu
Button Box( "OK", 
	answers = Eval List({selected_var = variablebox1_col_name << get selected});
	nw << close window;
),
Button Box( "Cancel")
), 

//change popup window size
<<Size Window(200,200)

	
);

 

What I am getting is the following in the resulting modal pop-up window. 

kachveder_0-1631473290010.png

 

I want the following pop-up window only to have the following: 

kachveder_1-1631473303846.png

 

 

 

I think my problem may have to do with a gap in my knowledge of associative arrays that I am having some trouble understanding completely, even though what the JMP scripting guide says about associative array keys and the remove from, remove, loc, and contains functions make sense. 

 

I want to make sure that the columns that are left in the resulting list that I used in the model window can be renamed by the user in the original dataset, so the column names that I want to remove will stay the same. Also, the arrangement of the columns in the data table is the same, but the associative array rearranges the values in ascending order. 

 

I used the following methods already, according to these forums, and there must be something that I am not seeing here because I am new to the JSL language. 

- removing elements from a list remove elements in a list 

- getting the column name from the column number and inputting the columns I selected into a list to be used. How to get column number from column name? (JMP) 

 

I have attached the toy dataset file which includes the script that I have referenced above. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: From a Selection of Column Names, how do I modify the resulting column name list

Here is the way I would solve this issue

Names Default To Here( 1 );

//get unique column names
cols = Current Data Table() << getColumnNames( Character, string );
//del columns I don't want
DELCOLS = {"Column 5", "Column 6"};
For( i = 1, i <= N Items( DELCOLS ), i++,
	Try( Remove From( cols, Contains( cols, DELCOLS[i] ) ) )
);
unique_col_names = cols;

//make a pop-up window
nw = New Window( "Set a Value",
	<<Modal,
	Text Box( "Set the character variable:" ),
	variablebox1_col_name = Radio Box( unique_col_names ),
	H List Box(
//get all saved variable values when the user 
		//selects the OK button from the menu
		Button Box( "OK", answers = selected_var = variablebox1_col_name << get selected ),
		Button Box( "Cancel" )
	)	
);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: From a Selection of Column Names, how do I modify the resulting column name list

Here is the way I would solve this issue

Names Default To Here( 1 );

//get unique column names
cols = Current Data Table() << getColumnNames( Character, string );
//del columns I don't want
DELCOLS = {"Column 5", "Column 6"};
For( i = 1, i <= N Items( DELCOLS ), i++,
	Try( Remove From( cols, Contains( cols, DELCOLS[i] ) ) )
);
unique_col_names = cols;

//make a pop-up window
nw = New Window( "Set a Value",
	<<Modal,
	Text Box( "Set the character variable:" ),
	variablebox1_col_name = Radio Box( unique_col_names ),
	H List Box(
//get all saved variable values when the user 
		//selects the OK button from the menu
		Button Box( "OK", answers = selected_var = variablebox1_col_name << get selected ),
		Button Box( "Cancel" )
	)	
);
Jim
kachveder
Level III

Re: From a Selection of Column Names, how do I modify the resulting column name list

Thanks so much! It worked great in my project and I learned what the Try() function is too.