cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
lwx228
Level VIII

How do I save a data table to TXT without column names?

Hello everyone:2018-09-22_08-31-58.png

How do I save a data table to TXT without column names?Thank you!

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: How do I save a data table to TXT without column names?

Here is a simple script that will do what you want

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

// Loop across all rows
For( i = 1, i <= N Rows( dt ), i++,
	// Copy all columns for the given row into a list
	rowVals = dt[i, 0];
	
	// Initialize a string variable
	theString = "";
	
	// Loop across all values in the row list, and place them into the string variable
	For( k = 1, k <= N Items( rowVals ), k++,
		If( k > 1,
			// After the first value, add a comma between the values
			theString = theString || ","
		);
		theString = theString || char(rowVals[k]);
	);
	
	// Add a new line character at the end of the line
	theString=theString||"\!n";
	
	// Write the row's values to the output txt file
	If(i==1,
		save text file("$TEMP/myfile.txt",theString,mode("replace")),
		save text file("$TEMP/myfile.txt",theString,mode("append"))
	)
);
Jim

View solution in original post

gzmorgan0
Super User (Alumni)

Re: How do I save a data table to TXT without column names?

An alternative is to change your export preferences, save the file and return the default preferences.

The script below contains the steps. It is documented in the JSL Companion, 2nd Ed. script 2_Extra_SaveText.jsl

Names Default to Here(1);

//Get a copy of the user's settings
_xx = Get Preference( Export settings);

//set the text export preferences you want
Preference(
	Export Settings(
		End Of Line( CRLF ),
		End Of Field( Comma, CSV( 1 ) ),
		Export Table Headers( 0 ),
		Quote all column names( 0 ),
		Quote all character values( 0 ),
		Quote all numeric values( 0 )
	)
);
//you can look at preferences now an they will be changed.

dt = Open("$Sample_data/Big Class.jmp");
dt << Save("c:/temp/bclass.txt");

//reset the user's preferences
_xx;

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: How do I save a data table to TXT without column names?

Here is a simple script that will do what you want

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

// Loop across all rows
For( i = 1, i <= N Rows( dt ), i++,
	// Copy all columns for the given row into a list
	rowVals = dt[i, 0];
	
	// Initialize a string variable
	theString = "";
	
	// Loop across all values in the row list, and place them into the string variable
	For( k = 1, k <= N Items( rowVals ), k++,
		If( k > 1,
			// After the first value, add a comma between the values
			theString = theString || ","
		);
		theString = theString || char(rowVals[k]);
	);
	
	// Add a new line character at the end of the line
	theString=theString||"\!n";
	
	// Write the row's values to the output txt file
	If(i==1,
		save text file("$TEMP/myfile.txt",theString,mode("replace")),
		save text file("$TEMP/myfile.txt",theString,mode("append"))
	)
);
Jim
lwx228
Level VIII

Re: How do I save a data table to TXT without column names?

Thank Jim!
It's just going to cycle like this.The same is true in VBA.
gzmorgan0
Super User (Alumni)

Re: How do I save a data table to TXT without column names?

An alternative is to change your export preferences, save the file and return the default preferences.

The script below contains the steps. It is documented in the JSL Companion, 2nd Ed. script 2_Extra_SaveText.jsl

Names Default to Here(1);

//Get a copy of the user's settings
_xx = Get Preference( Export settings);

//set the text export preferences you want
Preference(
	Export Settings(
		End Of Line( CRLF ),
		End Of Field( Comma, CSV( 1 ) ),
		Export Table Headers( 0 ),
		Quote all column names( 0 ),
		Quote all character values( 0 ),
		Quote all numeric values( 0 )
	)
);
//you can look at preferences now an they will be changed.

dt = Open("$Sample_data/Big Class.jmp");
dt << Save("c:/temp/bclass.txt");

//reset the user's preferences
_xx;
lwx228
Level VIII

Re: How do I save a data table to TXT without column names?

It's a masterpiece. Thank you very much!
lukasz
Level IV

Re: How do I save a data table to TXT without column names?

Hello,

Since I need to save certain string chains in separate lines in a text file, I tried the above solution of txnelson one to one, however it returns a file but with string chains saved in one line. It seems that the the newline character does not bring desired effect in my case. What am I missing?

Best regards

 

EDIT:

ok, instead of "\!n" I wrote "\!r\!n" and then worked as desired.

BrinaL
Level I

Re: How do I save a data table to TXT without column names?

I was also in need of solution for this. Thanks a lot for the soltion txnelson.