Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
lwx228
Level VII

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
Highlighted
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

Highlighted
gzmorgan0
Super User

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

5 REPLIES 5
Highlighted
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

Highlighted
lwx228
Level VII

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.
Highlighted
gzmorgan0
Super User

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

Highlighted
lwx228
Level VII

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

It's a masterpiece. Thank you very much!
Highlighted
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.

Article Labels

    There are no labels assigned to this post.