cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
mkennke
Level III

Script to transpose data in an existing data table

Hi,

I like to find a script to transpose data. And this data should be inserted at the last row of an existing file. Following how I transpose the data:

 

Data Table( "pisnapshot Abfrage AL2" ) << Transpose(

       columns( :value ),

       Transpose selected rows only( 1 ),

       Output Table( "AL2 Snapshot Transpose" )

);

Data Table( "pisnapshot Abfrage AL2" )

 

With that JMP copies the data every time a new Data Table. How is it possible to copy it into an existing File (File is open)?

I got the idea to select the transposed row ("AL2 Snapshot Transpose") and to copy it into my target file. But I was not able to find a command to copy the Row Values.

1 ACCEPTED SOLUTION

Accepted Solutions
mkennke
Level III

Re: Script to transpose data in an existing data table

Thank you for the fast response.

 

Meanwhile I tried something different. Therefore I used the function “concentrate”:

//transponse table
Data Table( "pisnapshot Abfrage AL2" ) << Transpose(
	columns( :value ),
	Transpose selected rows only( 1 ),
	Label( :tag ),
	Output Table( "AL2 Snapshot Transpose" ));

//add Table "AL2 Snapshot Transpose" to exsiting table "AL2 Snapshot"
Data Table( "AL2 Snapshot" ) << Concatenate(Data Table( "AL2 Snapshot Transpose" ),Append to first table);
//close table with “no save”
Close(Data Table( "AL2 Snapshot Transpose" ), No Save);

 

And it works perfectly. But I will try your solution .

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Script to transpose data in an existing data table

I think the script below is a simplier solution to what you stated you want

Names Default To Here( 1 );
dt = Current Data Table();

// Get the selected rows
selRows = dt << get selected rows;

If( N Rows( selRows ) > 0, 
// Add the row to place the data into
	dt << Add Rows( 1 );

// Go from column to column and move the selected data to the new row
	For( i = 1, i <= N Cols( dt ), i++,
		Column( dt, i )[N Rows( dt )] = Column( dt, N Col( dt ) )[selRows[i]]
	);

// Delete the last column
	dt << delete columns( Column( dt, N Cols( dt ) ) );
);
Jim
mkennke
Level III

Re: Script to transpose data in an existing data table

Thank you for the fast response.

 

Meanwhile I tried something different. Therefore I used the function “concentrate”:

//transponse table
Data Table( "pisnapshot Abfrage AL2" ) << Transpose(
	columns( :value ),
	Transpose selected rows only( 1 ),
	Label( :tag ),
	Output Table( "AL2 Snapshot Transpose" ));

//add Table "AL2 Snapshot Transpose" to exsiting table "AL2 Snapshot"
Data Table( "AL2 Snapshot" ) << Concatenate(Data Table( "AL2 Snapshot Transpose" ),Append to first table);
//close table with “no save”
Close(Data Table( "AL2 Snapshot Transpose" ), No Save);

 

And it works perfectly. But I will try your solution .

txnelson
Super User

Re: Script to transpose data in an existing data table

yours is a better solution if you have the ":Tag" column for the matching of column names
Jim