BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
JPKO

Community Trekker

Joined:

Jun 28, 2017

JSL: Save report by group into tabs

I am trying write a script that saves a report by groups into tabs. As an example let's consider a bivariate analysis of height vs weight in the Big Class example data set. I would like to carry out that analysis by column sex and output the analysis for :sex == "F" in one tab and :sex == "M" in another. Now this should of course work with any number of value levels in the groupby column. The only thing I can think of doing is to subset the datatable but then I end up with a bunch of data tables that I cannot close without loosing my report. Any suggestions on how to do this without subsetting?

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Re: JSL: Save report by group into tabs

Here is one way of doing it

tab.PNG

 

names default to here(1);
dt=open("$SAMPLE_DATA/big class.jmp");

// Generate the output in an invisible space
biv = dt << Bivariate( invisible, Y( :height ), X( :weight ), By( :sex ) );

// Create the window, with the first tab
nw=New Window("Tabs", text box("here are the tabs"), tb = Tab Box((report(biv[1])[outlinebox(1)])<<get title ,report(biv[1])));

// Generate the remaining tabs
For( i = 2, i <= N Items( biv ), i++,
	tb << Insert( i, (report(biv[i])[outlinebox(1)])<<get title, Report( biv[i] ) )
);

// Close the invisible output
biv<<close window;
Jim
3 REPLIES 3
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Re: JSL: Save report by group into tabs

Here is one way of doing it

tab.PNG

 

names default to here(1);
dt=open("$SAMPLE_DATA/big class.jmp");

// Generate the output in an invisible space
biv = dt << Bivariate( invisible, Y( :height ), X( :weight ), By( :sex ) );

// Create the window, with the first tab
nw=New Window("Tabs", text box("here are the tabs"), tb = Tab Box((report(biv[1])[outlinebox(1)])<<get title ,report(biv[1])));

// Generate the remaining tabs
For( i = 2, i <= N Items( biv ), i++,
	tb << Insert( i, (report(biv[i])[outlinebox(1)])<<get title, Report( biv[i] ) )
);

// Close the invisible output
biv<<close window;
Jim
Highlighted
danschikore

Staff

Joined:

Sep 21, 2012

Re: JSL: Save report by group into tabs

When you create a By() group, JMP is creating a set of subset tables for you automatically.  You can also do this on a level-by-level basis by using Where() clauses instead.

 

Here is a script that creates tabs per level, and as a bonus they are moveable and dockable, so they behave like a JMP Dashboard and can be rearranged in a variety of ways.

 

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

//get the unique levels
Summarize( dt, unique_values = by( :sex ) );

// Create the window with an empty tab list
nw = New Window( "Tabs", tb = Tab Box( <<Dockable( 1 ) ) );

// Generate tabs, one per level
For( i = 1, i <= N Items( unique_values ), i++,
	tb << Append(
		Tab Page Box(
			Title( ":sex = " || unique_values[i] ),
			dt << Bivariate( invisible, Y( :height ), X( :weight ), Where( :sex == unique_values[i] ) ),
			<<Moveable( 1 ),
			<<Closeable( 1 )
		)
	)
);
JPKO

Community Trekker

Joined:

Jun 28, 2017

Re: JSL: Save report by group into tabs

Thanks, both of you! Both solutions worked like a charm.