cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
CMG
CMG
Level II

Concat data in multiple text files with no headers

I have about 500 text files that I need to combine. All of them have no headers. The values are separated by comma as below. (the format is the same for all files)

 

122,3410732003,,ABC2,P
122,3410732003,,ABC2I,13.6
122,3410732020,,ABC2,P
122,3410732020,,ABC2I,4.13

 

So when I try to use the import multiple files option in JMP with csv settings, it warns me that there will be 500 data tables generated.

And when I tried importing the files using the text (one line per row), all the data is in one column.

Unfortunately, I don't know enough about scripting to write my own script. (I tried the attached script I found on this forum, but couldn't get it to work, I'm obviously doing something wrong!)

Any and all help in this is greatly appreciated!

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Concat data in multiple text files with no headers

Something like this should work:

Names Default To Here(1);

path = "C:\WIP\All text files\"; //note ending \

fileList = Files In Directory(path);

//use first table as "base datatable" to concatenate to
dt = Open(
	path || fileList[1],
	columns(
		New Column("c000001", Numeric, "Continuous", Format("Best", 12)),
		New Column("c000002", Numeric, "Continuous", Format("Best", 12)),
		New Column("c000003", Numeric, "Continuous", Format("Best", 12)),
		New Column("c000004", Character, "Nominal"),
		New Column("c000005", Character, "Nominal")
	),
	Import Settings(
		End Of Line(CRLF, CR, LF),
		End Of Field(Comma, CSV(0)),
		Strip Quotes(1),
		Use Apostrophe as Quotation Mark(0),
		Use Regional Settings(0),
		Scan Whole File(1),
		Treat empty columns as numeric(0),
		CompressNumericColumns(0),
		CompressCharacterColumns(0),
		CompressAllowListCheck(0),
		Labels(0),
		Column Names Start(1),
		Data Starts(1),
		Lines To Read("All"),
		Year Rule("20xx")
	)
);

//start from 2 because we already have file 1 as dt
For(i = 2, i <= N items(fileList), i++,
	dt_temp = Open(
			path || fileList[i],
			columns(
				New Column("c000001", Numeric, "Continuous", Format("Best", 12)),
				New Column("c000002", Numeric, "Continuous", Format("Best", 12)),
				New Column("c000003", Numeric, "Continuous", Format("Best", 12)),
				New Column("c000004", Character, "Nominal"),
				New Column("c000005", Character, "Nominal")
			),
			Import Settings(
				End Of Line(CRLF, CR, LF),
				End Of Field(Comma, CSV(0)),
				Strip Quotes(1),
				Use Apostrophe as Quotation Mark(0),
				Use Regional Settings(0),
				Scan Whole File(1),
				Treat empty columns as numeric(0),
				CompressNumericColumns(0),
				CompressCharacterColumns(0),
				CompressAllowListCheck(0),
				Labels(0),
				Column Names Start(1),
				Data Starts(1),
				Lines To Read("All"),
				Year Rule("20xx")
			)
		);
	dt << Concatenate(dt_temp, Append to first table);
	Close(dt_temp, no save);
);
-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Concat data in multiple text files with no headers

Something like this should work:

Names Default To Here(1);

path = "C:\WIP\All text files\"; //note ending \

fileList = Files In Directory(path);

//use first table as "base datatable" to concatenate to
dt = Open(
	path || fileList[1],
	columns(
		New Column("c000001", Numeric, "Continuous", Format("Best", 12)),
		New Column("c000002", Numeric, "Continuous", Format("Best", 12)),
		New Column("c000003", Numeric, "Continuous", Format("Best", 12)),
		New Column("c000004", Character, "Nominal"),
		New Column("c000005", Character, "Nominal")
	),
	Import Settings(
		End Of Line(CRLF, CR, LF),
		End Of Field(Comma, CSV(0)),
		Strip Quotes(1),
		Use Apostrophe as Quotation Mark(0),
		Use Regional Settings(0),
		Scan Whole File(1),
		Treat empty columns as numeric(0),
		CompressNumericColumns(0),
		CompressCharacterColumns(0),
		CompressAllowListCheck(0),
		Labels(0),
		Column Names Start(1),
		Data Starts(1),
		Lines To Read("All"),
		Year Rule("20xx")
	)
);

//start from 2 because we already have file 1 as dt
For(i = 2, i <= N items(fileList), i++,
	dt_temp = Open(
			path || fileList[i],
			columns(
				New Column("c000001", Numeric, "Continuous", Format("Best", 12)),
				New Column("c000002", Numeric, "Continuous", Format("Best", 12)),
				New Column("c000003", Numeric, "Continuous", Format("Best", 12)),
				New Column("c000004", Character, "Nominal"),
				New Column("c000005", Character, "Nominal")
			),
			Import Settings(
				End Of Line(CRLF, CR, LF),
				End Of Field(Comma, CSV(0)),
				Strip Quotes(1),
				Use Apostrophe as Quotation Mark(0),
				Use Regional Settings(0),
				Scan Whole File(1),
				Treat empty columns as numeric(0),
				CompressNumericColumns(0),
				CompressCharacterColumns(0),
				CompressAllowListCheck(0),
				Labels(0),
				Column Names Start(1),
				Data Starts(1),
				Lines To Read("All"),
				Year Rule("20xx")
			)
		);
	dt << Concatenate(dt_temp, Append to first table);
	Close(dt_temp, no save);
);
-Jarmo
CMG
CMG
Level II

Re: Concat data in multiple text files with no headers

Thank you very much! That was a huge help!

Re: Concat data in multiple text files with no headers

You can interactively perform this operation with Files > Import Multiple Files using JMP 15. See the JMP documentation about this facility. You can use this command in a script, too.