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

How to loop tabulated tables and images into ppt slides

Hi, I am kinda stuck and struggling in JMP looping. How can I loop a tabulated table that came from my subset tables? The number of tables may change so I figured that I needed to do looping (but Im struggling) also I need this images appended to powerpoint slides. I don't have an idea how to get looped variable name and append it to the slides.

 

Here's my sample script, but doesn't have any looping. Is it possible?

 

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

:Sex << Set Name( "Sex_Subset" );
dt << New Column( "Sex", Formula(:Sex_Subset));

dt1 = dt << Subset( By( :Sex_Subset ), All rows, Selected columns only( 0 ) );

//this is where to loop tabulated tables since column values used in subsetting dt may change number of values
 
//how to loop this according to data table name? is that possible?
dt_Tab = Tabulate(
	Add Table(
		Column Table( Grouping Columns( :Sex ), Analysis Columns( :height ) ),
		Row Table( Grouping Columns( :name, :age ) )
	)
);

tab = dt_Tab << get picture; //variable name needs to be looped? for ppt slides


//after getting the plot as image, how can I append those images that were loop to ppt slides?

//for male table
hbppt1 = H List Box(tab) << get picture;
ppt1 = Outline Box( "Male", hbppt1 );
ppt1 << savepresentation( pathppt, append, PNG );

//for female table
hbppt2 = H List Box(tab2) << get picture;
ppt2 = Outline Box( "Female", hbppt2 );
ppt2 << savepresentation( pathppt, append, PNG );

tables from subset

 

3 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: How to loop tabulated tables and images into ppt slides

If you use Subset with By, you will get a list of tables which you can then loop over

dt1 = {DataTable("Sex_Subset=F"), DataTable("Sex_Subset=M")};

 

Edit:

Check scripting index for your functions and messages you are using, some of them are incorrect

Names Default To Here(1);

pathppt = "$TEMP/bigclass.pptx";

dt = Open("$SAMPLE_DATA/Big Class.jmp");
Column(dt, "Sex") << Set Name("Sex_Subset");
dt << New Column("Sex", Formula(:Sex_Subset));

dt_subsets = dt << Subset(By(:Sex_Subset), All rows, Selected columns only(0));

For Each({dt_subset}, dt_subsets,
	subset_tab = dt_subset << Tabulate(
		Add Table(
			Column Table(Grouping Columns(:Sex), Analysis Columns(:height)),
			Row Table(Grouping Columns(:name, :age))
		)
	);

	tab_pic = subset_tab << get picture; 
	subset_tab << Close Window;
	name_dt = dt_subset << get name;
	Close(, no save);
	hbppt = H List Box(tab_pic) << get picture;
	ppt = Outline Box(name_dt, hbppt);
	If(!File Exists(pathppt), 
		ppt << savepresentation(pathppt);
	, // append only if file already exists
		ppt << savepresentation(pathppt, append);
	);
);
 
Open(pathppt);
-Jarmo

View solution in original post

txnelson
Super User

Re: How to loop tabulated tables and images into ppt slides

Here is a rework of your script that creates the slides

txnelson_0-1696412637351.png

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

// Specify the path to save the pptx's to
pathPPT = "$TEMP/UserID16644Slides.pptx";

:Sex << Set Name( "Sex_Subset" );
dt << New Column( "Sex", Formula( :Sex_Subset ) );

// Add value labels so the full value can be used for the slide title
dt:Sex_Subset << Value Labels( {"F" = "Female", "M" = "Male"} ) << Use Value Labels( 1 );

// Subset the tables.  The dataTableList will contain a reference to each table created
dataTableList = dt << Subset( By( :Sex_Subset ), All rows, Selected columns only( 0 ) );

// Loop across all of the tables and create the Tabulates
For Each( {table, i}, dataTableList, 

	dt_Tab = table << Tabulate(
		Add Table(
			Column Table( Grouping Columns( :Sex ), Analysis Columns( :height ) ),
			Row Table( Grouping Columns( :name, :age ) )
		)
	);

	// Pull the subset name from the data table name
	theTitle = Word( 3, Char( dataTableList[i] ), "\!"=" );
	
	// Create the new slide
	hbppt1 = H List Box( dt_tab  << get picture);
	ppt1 = Outline Box( theTitle, hbppt1 );
	
	// The pptx must exist for the append to be used, so on the first
	// slide it is not appended
	if(i==1,
		ppt1 << savepresentation( pathppt,"PNG" ),
		ppt1 << savepresentation( pathppt, Append,"PNG" )
	);
);

// Open the powerpoint presentation to see the results
open(pathppt);

 

Jim

View solution in original post

UserID16644
Level V

Re: How to loop tabulated tables and images into ppt slides

I see. Also, just wondering where did dt_subset came from?

UserID16644_0-1696472716119.png

 

Because as I tried this line of code, dt_subset (dt_subset << Tabulate() )is not found. However, I tried replacing it with dt_subsets, it tabulated the tables 2x (2 tabulated tables for male and 2 for female)

For (i = 1, i <= N Items( dt_subsets ), i++,
	subset_tab = dt_subset << Tabulate(
		Add Table(
			Column Table(Grouping Columns(:Sex), Analysis Columns(:height)),
			Row Table(Grouping Columns(:name, :age))
		)
	);
);

View solution in original post

8 REPLIES 8
jthi
Super User

Re: How to loop tabulated tables and images into ppt slides

If you use Subset with By, you will get a list of tables which you can then loop over

dt1 = {DataTable("Sex_Subset=F"), DataTable("Sex_Subset=M")};

 

Edit:

Check scripting index for your functions and messages you are using, some of them are incorrect

Names Default To Here(1);

pathppt = "$TEMP/bigclass.pptx";

dt = Open("$SAMPLE_DATA/Big Class.jmp");
Column(dt, "Sex") << Set Name("Sex_Subset");
dt << New Column("Sex", Formula(:Sex_Subset));

dt_subsets = dt << Subset(By(:Sex_Subset), All rows, Selected columns only(0));

For Each({dt_subset}, dt_subsets,
	subset_tab = dt_subset << Tabulate(
		Add Table(
			Column Table(Grouping Columns(:Sex), Analysis Columns(:height)),
			Row Table(Grouping Columns(:name, :age))
		)
	);

	tab_pic = subset_tab << get picture; 
	subset_tab << Close Window;
	name_dt = dt_subset << get name;
	Close(, no save);
	hbppt = H List Box(tab_pic) << get picture;
	ppt = Outline Box(name_dt, hbppt);
	If(!File Exists(pathppt), 
		ppt << savepresentation(pathppt);
	, // append only if file already exists
		ppt << savepresentation(pathppt, append);
	);
);
 
Open(pathppt);
-Jarmo
UserID16644
Level V

Re: How to loop tabulated tables and images into ppt slides

Hi, I tried converting the For Each loop to For but doesn't get an output

For (i = 1, i <= dt_subsets, i++,
	subset_tab = dt_subset << Tabulate(
		Add Table(
			Column Table(Grouping Columns(:Sex), Analysis Columns(:height)),
			Row Table(Grouping Columns(:name, :age))
		)
	);
);
txnelson
Super User

Re: How to loop tabulated tables and images into ppt slides

dt_subsets is a JMP list.  what you need is the number of elements in the list.

For (i = 1, i <= N Items( dt_subsets ), i++,
	subset_tab = dt_subsets << Tabulate(
		Add Table(
			Column Table(Grouping Columns(:Sex), Analysis Columns(:height)),
			Row Table(Grouping Columns(:name, :age))
		)
	);
);
Jim
UserID16644
Level V

Re: How to loop tabulated tables and images into ppt slides

I see. Also, just wondering where did dt_subset came from?

UserID16644_0-1696472716119.png

 

Because as I tried this line of code, dt_subset (dt_subset << Tabulate() )is not found. However, I tried replacing it with dt_subsets, it tabulated the tables 2x (2 tabulated tables for male and 2 for female)

For (i = 1, i <= N Items( dt_subsets ), i++,
	subset_tab = dt_subset << Tabulate(
		Add Table(
			Column Table(Grouping Columns(:Sex), Analysis Columns(:height)),
			Row Table(Grouping Columns(:name, :age))
		)
	);
);
txnelson
Super User

Re: How to loop tabulated tables and images into ppt slides

The variable 

dt_subset

is an error, it needs to be

dt_subsets

Jim
txnelson
Super User

Re: How to loop tabulated tables and images into ppt slides

Here is a rework of your script that creates the slides

txnelson_0-1696412637351.png

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

// Specify the path to save the pptx's to
pathPPT = "$TEMP/UserID16644Slides.pptx";

:Sex << Set Name( "Sex_Subset" );
dt << New Column( "Sex", Formula( :Sex_Subset ) );

// Add value labels so the full value can be used for the slide title
dt:Sex_Subset << Value Labels( {"F" = "Female", "M" = "Male"} ) << Use Value Labels( 1 );

// Subset the tables.  The dataTableList will contain a reference to each table created
dataTableList = dt << Subset( By( :Sex_Subset ), All rows, Selected columns only( 0 ) );

// Loop across all of the tables and create the Tabulates
For Each( {table, i}, dataTableList, 

	dt_Tab = table << Tabulate(
		Add Table(
			Column Table( Grouping Columns( :Sex ), Analysis Columns( :height ) ),
			Row Table( Grouping Columns( :name, :age ) )
		)
	);

	// Pull the subset name from the data table name
	theTitle = Word( 3, Char( dataTableList[i] ), "\!"=" );
	
	// Create the new slide
	hbppt1 = H List Box( dt_tab  << get picture);
	ppt1 = Outline Box( theTitle, hbppt1 );
	
	// The pptx must exist for the append to be used, so on the first
	// slide it is not appended
	if(i==1,
		ppt1 << savepresentation( pathppt,"PNG" ),
		ppt1 << savepresentation( pathppt, Append,"PNG" )
	);
);

// Open the powerpoint presentation to see the results
open(pathppt);

 

Jim
UserID16644
Level V

Re: How to loop tabulated tables and images into ppt slides

I do not have JMP 16 yet, I tried converting For Each loop to For loop but I don't get any output

For (i = 1, i <= dataTableList, i++,
	dt_Tab = table << Tabulate(
		Add Table(
			Column Table( Grouping Columns( :Sex ), Analysis Columns( :height ) ),
			Row Table( Grouping Columns( :name, :age ) )
		)
	);
);
txnelson
Super User

Re: How to loop tabulated tables and images into ppt slides

It needs to be

For (i = 1, i <= N Items( dataTableList ), i++,
Jim