cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar

Exporting full LCA dataset to CSV/Excel

I conducted an LCA analysis on survey questions. In the "parameter estimates" section of the generated report, there is a table. When I export it, it doesn't export the merged cells on top. For example:

Cluster 1:  [Top Column: State]

                   [AZ] [VA], [DC], [TX]

 

It only exports the cluster, and the parameter estimates for [AZ] [VA], [DC], [TX]. I want to export every visible thing, including the top column with merged cells. 

2 REPLIES 2
txnelson
Super User

Re: Exporting full LCA dataset to CSV/Excel

I hope someone in the Community has a better solution than what I have come up with.  I am not aware of a direct way to add the spanning headers to the column headers in an output data table.  However I have written an example script that can do what you want.

It takes an LCA analysis output

txnelson_0-1707103154843.png

and output the Parameter Estimates table with the Spanning Headers prefixed to each column

txnelson_2-1707103752206.png

Here is the example script

Names Default To Here( 1 );

// Run a LCA
dt = Open( "$SAMPLE_DATA/Car Poll.jmp" );
dt << Latent Class Analysis(
	Y( :sex, :marital status, :country, :size, :type ),
	Set Random Seed( 12345 ),
	Number of Clusters( 3 ),
);

// Create an output table will all header names in each column's name
obj = current report()[OutlineBox(1)];
// Get the number of tiles that span across columns
numSpans = Length( (obj  << xpath( "//ColSpanBox" )) );

// Loop across the spanning titles and add the title as a prefix to the column name
For( span = 1, span <= numSpans, span++,
	// Get the header
	theHeading = obj["Parameter Estimates"][Col Span Box( span )] << get heading;
	// Get the column names for the current spanning header
	theCols = obj["Parameter Estimates"][Col Span Box( span )] << get text;
	// Loop across each column name in the span
	subColNum = 1;
	While( Try( Word( subColNum, theCols, "\!n\!t\!r" ), "" ) != "",
		targetCol = Word( subColNum, theCols, "\!n\!t\!r" );
		// Loop across all numeric column and when a match is found change the column name
		numCol = 2;
		While(
			Try( obj["Parameter Estimates"][Number Col Box( numCol )] << get heading, "" )
			 != "",
			theNumberColBoxHeader = obj["Parameter Estimates"][Number Col Box( numCol )]
			 << get heading;
			If( targetCol == theNumberColBoxHeader,
				obj["Parameter Estimates"][Number Col Box( numCol )] <<
				set heading( theHeading || " " || targetCol )
			);
			numCol++;
		);
		subColNum++;
	);
);

// Create the output data table
obj["Parameter Estimates", Table Box( 1 )] << Make into data table;

 

 

Jim

Re: Exporting full LCA dataset to CSV/Excel

That is impressive @txnelson you have no idea how much time you have helped me save. Kudos to you, sir!

Recommended Articles