cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
tmj
tmj
Level II

How to save column entries to text file without quotes on each line

Hello....I'm trying to save off column entries to text file without column name. These text files are used by VB code in another existing program that expects the fields in each line to be separated by commas. I'm able to get the text files created without the column name (thanks to another user's previous post!) but I can't get the code to not put quotes around the entries for each line. I've tried several options in "End of Field", but all still adding quotes. I know if I change the delimiter in each line to be something other than comma (ex. ".") then I can get the JSL code to not add the quotes, but the external VB code is expected "," delimiter and difficult to change as it is legacy code used by many. Any ideas how to keep out the quotes while still maintaining the comma delimiter in each line? I could of course remove them in editor, but there can be many of these txt files generated. JMP ver 16.2, Win10.

 

Example:

tmj_0-1688569312146.png

 

I need it like this:

MD16616,1,23,3,
MD16616,1,26,4,
MD16616,1,22,4,
MD16616,1,23,4,
MD16616,1,16,2,
MD16616,1,11,6,
MD16616,1,24,7,

 

dt << Select Where(As Column(groupColName) == groupNames[i]);
		sortdt = dt << Subset(Selected Rows, Columns(:ECIDSort));
		sortfile = ECIDListPath||"\WaferSort_"||GroupNames[i]||".txt";
			
		//Save ecid sort files, to get in correct format, need to changes export preferences, but don't worry, we'll set them back the way they were
		_xx = Get Preference(Export settings);
		Preference(
			Export Settings(
				End Of Line( CRLF ),
				//End Of Field( Comma ),
				End of Field(Comma, CSV(0)),
				//End Of Field( Space, CSV( 0 ) ),
				Export Table Headers( 0 ),
				Quote all column names( 0 ),
				Quote all character values( 0 ),
				Quote all numeric values( 0 )
			)
		);
		sortdt << Save As(sortfile);
		_xx; //reset preferences
		close(sortdt, no save); 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to save column entries to text file without quotes on each line

How does your data table look like? Something like this?

jthi_0-1688570959637.png

or like this?

jthi_1-1688571204040.png

 

One option would be to build a string and then save that using save text file().

Names Default To Here(1);

dt = New Table("Untitled 2",
	Add Rows(7),
	Compress File When Saved(1),
	New Column("Column 1",
		Character,
		"Nominal",
		Set Values(
			{"MD16616,1,23,3,", "MD16616,1,26,4,", "MD16616,1,22,4,", "MD16616,1,23,4,", "MD16616,1,16,2,", "MD16616,1,11,6,",
			"MD16616,1,24,7,"}
		)
	)
);

save_str = "";
For Each Row(dt,
	save_str ||= :Column 1 ||"\!N"
);

Save Text File("$DOWNLOADS/text.txt", save_str);

You might have to use different row changes or remove last row change depending on your other application.

 

Also if you manipulate users preferences, you should save them to temporary file, there will be cases where JMP will for example crash before you are able to set them back.

-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: How to save column entries to text file without quotes on each line

How does your data table look like? Something like this?

jthi_0-1688570959637.png

or like this?

jthi_1-1688571204040.png

 

One option would be to build a string and then save that using save text file().

Names Default To Here(1);

dt = New Table("Untitled 2",
	Add Rows(7),
	Compress File When Saved(1),
	New Column("Column 1",
		Character,
		"Nominal",
		Set Values(
			{"MD16616,1,23,3,", "MD16616,1,26,4,", "MD16616,1,22,4,", "MD16616,1,23,4,", "MD16616,1,16,2,", "MD16616,1,11,6,",
			"MD16616,1,24,7,"}
		)
	)
);

save_str = "";
For Each Row(dt,
	save_str ||= :Column 1 ||"\!N"
);

Save Text File("$DOWNLOADS/text.txt", save_str);

You might have to use different row changes or remove last row change depending on your other application.

 

Also if you manipulate users preferences, you should save them to temporary file, there will be cases where JMP will for example crash before you are able to set them back.

-Jarmo
tmj
tmj
Level II

Re: How to save column entries to text file without quotes on each line

Data table in JMP looks like the 2nd you showed. Your solution works perfectly. Thanks very much! And duly noted on the preferences change...hadn't thought about crash scenario.

Re: How to save column entries to text file without quotes on each line

I think the embedded commas in the text field are treated as special characters. Whenever special characters are in the text, they will be enclosed in double-quotes on export, regardless of how you set the preferences. I do not know of a workaround other than to remove the commas and replace them with blanks or underscores. The "Replace String..." red triangle option in the Recode platform can help with this.