How do I save a data table to TXT without column names?Hello everyone:
How do I save a data table to TXT without column names?Thank you!
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.
Re: How do I save a data table to TXT without column names?It's a masterpiece. Thank you very much!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;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.
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.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"))
)
);