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

JSL : Use a checkbox with the levels of a column

Hello,

 

I hope you are doing well.

 

I have a question about the scripts of the checkboxes in JMP.

 

I have a data set with a "strength" variable, and I want to create a subset if the data set according to a checkbox presenting all the strengths in the data set. The aim is that the user check in the checkbox the strengths of interest and that the rows in the data set are selected according to the strengths checked in the checkbox. As the strengths are not necessary the same according to the data set,  I was wondering if it is possible to "extract" the unique values of strengths from the column and then to present the strengths in the checkbox in order to choose in the checkbox the strengths of interest. I want to have the script as general as possible to analyze all data sets with all possible strengths.

 

Thank you very much and have a nice day,

 

Jean

1 ACCEPTED SOLUTION

Accepted Solutions
David_Burnham
Super User (Alumni)

Re: JSL : Use a checkbox with the levels of a column

An alternative example:

 

Names Default to Here( 1 );

// mock up data set with Strength
dt = New Table( "Strength",
	New Column( "Strength", "Character", "Nominal",
		Values( {"Intelligent", "Innovative", "Initiative", "Introvert", "Intelligent",
			"Innovative", "Initiative", "Introvert", "Intelligent", "Innovative",
			"Initiative", "Introvert"} )
	)
);

// get unique values from the strength column
summarize(dt,levels=by(:strength));

// construct a window containing checkboxes
NewWindow("Selection",
	BorderBox(top(20),bottom(20),left(20),right(20),
		VListBox(
			TextBox("Select values:"),
			here:cb = CheckBox(levels),
			SpacerBox(size(0,20)),
			ButtonBox("Create Subset",doSubset())
		)
	)
);

// define function to perform when button is cliccked

doSubset = function({},{default local},

		dt = current data table();
		dt << clear select;

		// get user selections
		selected = here:cb << get selected;
		
		// iterate over each of the selected values
		// and select the associated rows
		for each( {selection},selected,
			rows = dt << select  where(:Strength==selection,
				current selection("extend")
			);
		);
		// create a subset table
		dt << subset(
			selected rows(1),
			selected columns only(0)
		);
		dt << clear select;

);

 

-Dave

View solution in original post

9 REPLIES 9

Re: JSL : Use a checkbox with the levels of a column

This example illustrates an approach that might work.

 

Names Default to Here( 1 );

// mock up data set with Strength
dt = New Table( "Strength",
	New Column( "Strength", "Character", "Nominal",
		Values( {"Intelligent", "Innovative", "Initiative", "Introvert", "Intelligent",
			"Innovative", "Initiative", "Introvert", "Intelligent", "Innovative",
			"Initiative", "Introvert"} )
	)
);

// present user with choices
choice = Associative Array( :Strength ) << Get Keys;
New Window( "Choose Strengths",
	Outline Box( "Pick Your Strengths from the Choices Below",
		Panel Box( "Strengths",
			Check Box( choice,
				<< Set Function(
					Function( { me, index }, { Default Local },
						selection = me << Get Selected;
						n = N Items( selection );
						dt << Clear Select;
						If(
							n == 1,
								Eval(
									Substitute(
										Expr( dt << Select Where( :Strength == sss ) ),
										Expr( sss ), Name Expr( selection[1] )
									)
								),
							n > 0,
								sel expr = Expr( Or() );
								For( i = 1, i <= n, i++,
									equality = Substitute(
										Expr( :Strength == ccc ),
										Expr( ccc ), selection[i]
									);
									Insert Into( sel expr, Name Expr( equality ) );
								);
								Eval(
									Substitute(
										Expr( dt << Select Where( eee ) ),
										Expr( eee ), Name Expr( sel expr )
									)
								);
						);
					);
				)
			)
		)
	)
);
David_Burnham
Super User (Alumni)

Re: JSL : Use a checkbox with the levels of a column

An alternative example:

 

Names Default to Here( 1 );

// mock up data set with Strength
dt = New Table( "Strength",
	New Column( "Strength", "Character", "Nominal",
		Values( {"Intelligent", "Innovative", "Initiative", "Introvert", "Intelligent",
			"Innovative", "Initiative", "Introvert", "Intelligent", "Innovative",
			"Initiative", "Introvert"} )
	)
);

// get unique values from the strength column
summarize(dt,levels=by(:strength));

// construct a window containing checkboxes
NewWindow("Selection",
	BorderBox(top(20),bottom(20),left(20),right(20),
		VListBox(
			TextBox("Select values:"),
			here:cb = CheckBox(levels),
			SpacerBox(size(0,20)),
			ButtonBox("Create Subset",doSubset())
		)
	)
);

// define function to perform when button is cliccked

doSubset = function({},{default local},

		dt = current data table();
		dt << clear select;

		// get user selections
		selected = here:cb << get selected;
		
		// iterate over each of the selected values
		// and select the associated rows
		for each( {selection},selected,
			rows = dt << select  where(:Strength==selection,
				current selection("extend")
			);
		);
		// create a subset table
		dt << subset(
			selected rows(1),
			selected columns only(0)
		);
		dt << clear select;

);

 

-Dave

Re: JSL : Use a checkbox with the levels of a column

Hi David, thank you very much for your help!

 

However, when the code is executed, I have ther following error :

PersuasionCamel_0-1667234770749.png

How can I fix it?

 

Thank you very much and have a nice day,

 

Jean

David_Burnham
Super User (Alumni)

Re: JSL : Use a checkbox with the levels of a column

'for each' is new to version 16.  If you have an older version then you can use a more traditional for-loop:

 

		for (i=1,i<=nitems(selected),i++,
			rows = dt << select  where(:Strength==selected[i],
				current selection("extend")
			);			
		);
-Dave

Re: JSL : Use a checkbox with the levels of a column

Thank you very much !

 

Two last questions:

- Is there any command to close or hide the subset of the data set ?

- If I have already a dataset opened in Jmp, how can I defined it in a dt variable?

 

Thank you very much and have a nice day,

 

Jean

Re: JSL : Use a checkbox with the levels of a column

Thank you very much ! Is the subset stored in the dt2 variable ?

David_Burnham
Super User (Alumni)

Re: JSL : Use a checkbox with the levels of a column

Is the subset stored in the dt2 variable 

Only if you define a dt2 variable

You can do this:

		dt2 = dt << subset(
			selected rows(1),
			selected columns only(0)
		);

Is there any command to close or hide the subset of the data set 

Since we've only just created it I assume we don't want to close it, but if you don't want the user to see it you can make it invisible:

		dt2 = dt << subset( invisible,
			selected rows(1),
			selected columns only(0)
		);

If I have already a dataset opened in Jmp, how can I defined it in a dt variable

You can either associate the dt variable to the current open table,

dt = current data table();

or if there are multiple tables open, by referencing the table:

dt = data table("strength data");

Finally, a question you didn't ask but might be wondering.  Once the user has clicked the button to create the subset, if you want to close the window containing the checkboxes you can add the following lines to the end of the doSubset function:

cr = current report();
cr << close window;

Good luck.

 

-Dave

Re: JSL : Use a checkbox with the levels of a column

All good !

 

Thank you so much !

 

Have a very nice day,

 

Jean

Re: JSL : Use a checkbox with the levels of a column

Hello again,

 

I have a very last question: how can I modify the code to name each subset by the strengths that were checked in the checkbox ?

 

Thank you so much and have a nice day,

 

Jean