cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.
  • JMP will suspend normal business operations for our Rest and Recharge Day on Friday, October 2, 2026.
    Regular business hours will resume on Monday, October 5, 2026.

Discussions

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

moving a few columns/rows from table a to b

Clear Symbols();
// Open a file dialog to choose the text file
txtFilePath = Pick File("Choose a text file", {"Text Files|*.txt"});
 
// Check if a file was selected
If(txtFilePath != "", 
    // Convert the file path to ensure it's in the correct format
	txtFilePath = Convert File Path(txtFilePath);
 
    // Import the text file into a new JMP table
	dt1 = Open(
		txtFilePath,
		Delimiter("\t") // Change delimiter if necessary
	);
 
    // Specify the row to use for column names (e.g., row 1)
	columnNamesRow = 16;
 
    // Specify the columns to extract (e.g., columns 1, 2, 3)
	columnsToExtract = {1, 17, 18, 22}; // Adjust column indices as needed
 
	// Extract the column names from the specified row and columns
   
	columnNamesList = {};
	For(j = 1, j <= N Items(columnsToExtract), j++,
		colIndex = columnsToExtract[j];
		columnNamesList[j] = :Column(colIndex)[columnNamesRow];
	);
    
   
    // Create a new JMP table with the extracted column names
	dt2 = New Table("Converted Table");
 
    
  
	For(i = 1, i <= N Items(columnNamesList), i++,
		dt2 << New Column(Char(columnNamesList[i]), Character); // Adjust column type as needed
	);
 
    // Specify the rows to extract (e.g., rows 2 to 10)
	startRow = 17;
	endRow = 65;
//
	// Loop through the specified rows and add them to the JMP table
	For(i = startRow, i <= endRow, i++,
		dt2 << Add Rows(1);
		For(j = 1, j <= N Items(columnsToExtract), j++,
			colIndex = columnsToExtract[j];
           
			dt2:Column(j)[i - startRow + 1] = dt1:Column(colIndex)[i];
		);
	);
 
    // Close the imported table
	Close(dt1);
, 
    // If no file was selected, show a message
	Show Message("No file selected.")
);
I am getting a same error messages: 

Scoped data table access requires a data table column or variable at row 1 in access or evaluation of 'dt1:Column' , dt1:Column( colIndex ) /*###*/

at line 49

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: moving a few columns/rows from table a to b

Syntax for referencing to columns is incorrect (you are combining Column() and As Column() (the table:column syntax)).

Changing

dt2:Column(j)[i - startRow + 1] = dt1:Column(colIndex)[i];

to

Column(dt2, j)[i - startRow + 1] = Column(dt1, colIndex)[i];

might work.

 

Also, there might be easier methods to do what you want to achieve but it would require for us to see an example file and the wanted result.

-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: moving a few columns/rows from table a to b

Syntax for referencing to columns is incorrect (you are combining Column() and As Column() (the table:column syntax)).

Changing

dt2:Column(j)[i - startRow + 1] = dt1:Column(colIndex)[i];

to

Column(dt2, j)[i - startRow + 1] = Column(dt1, colIndex)[i];

might work.

 

Also, there might be easier methods to do what you want to achieve but it would require for us to see an example file and the wanted result.

-Jarmo
hogi
Level XIII

Re: moving a few columns/rows from table a to b

As Jarmo indicates, for some of the steps, JMP provides pre-defined modules.

 

By using such modules:

  • the code gets shorter and easier to understand
  • JMP handles the data types automatically
  • the execution is much faster
txtFilePath = "$SAMPLE_IMPORT_DATA/Animals_line3.txt";
columnNamesRow = 3;
columnsToExtract = {"species", "miles"};
startRow = 2;
endRow = 10;

dt1 = Open( txtFilePath, 
	Import Settings( Labels( 0 ) )
);
wait(0); //let JMP relax before it continues with the next steps
if(columnNamesRow>1, dt1 << delete rows( 1 :: (columnNamesRow - 1) ));
dt1 << move up; dt2 = dt1 << Subset( Rows( startRow :: endRow ), columns( columnsToExtract ) );

 

Recommended Articles