cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
mlo1
Level IV

How to Skip charater to import column header

I am having data in a txt file .

What is the best option to read in the data into a JMP table with skipping the # character to get the column names fitting to the data columns?

Any recommendations ?

 

mlo1_0-1674806513024.png

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
julian
Community Manager Community Manager

Re: How to Skip charater to import column header

Hi @mlo1,

 

I don't know of a non-scripting way during import to ignore a character like that. Preprocessing the file to remove the # is probably the most direct approach if you can do it. I've been in a situation like this before where editing the original file wasn't possible/preferable, and so another approach would be to fix the names after the import. The following shifts all the column names left and removes the blank last column.

 

dt = Current Data Table();

//get all the column names
colNames = dt << Get Column Names( String );

//remove the last column with no data
dt << Delete Columns( N Cols( dt ) );

//loop to replace names starting at the end of the table
For( c = N Cols( dt ), c > 0, c--,
	Column( c ) << Set Name( colNames[c+1] )
);

 

I hope this helps!

@julian 

 

View solution in original post

jthi
Super User

Re: How to Skip charater to import column header

Here is other option which relies on removing few extra characters and then "opening the file" again by using Char To Blob()

Names Default To Here(1);

txt = Load Text File("$DOWNLOADS/JMPTest.txt");
txt = Substr(txt, 3, - 1); // drop first three characters
dt = Open(
	Char To Blob(txt),
	End Of Field(Spaces, Space, CSV(0))
);
-Jarmo

View solution in original post

7 REPLIES 7
jthi
Super User

Re: How to Skip charater to import column header

Could you share the text file (or mock-up of it)? Makes it much easier to provide suggestions. First idea that comes to my mind is to drop some characters from the data with the help of JSL

-Jarmo
mlo1
Level IV

Re: How to Skip charater to import column header

Thank you for the reply I enclosed a sample file.

julian
Community Manager Community Manager

Re: How to Skip charater to import column header

Hi @mlo1,

 

I don't know of a non-scripting way during import to ignore a character like that. Preprocessing the file to remove the # is probably the most direct approach if you can do it. I've been in a situation like this before where editing the original file wasn't possible/preferable, and so another approach would be to fix the names after the import. The following shifts all the column names left and removes the blank last column.

 

dt = Current Data Table();

//get all the column names
colNames = dt << Get Column Names( String );

//remove the last column with no data
dt << Delete Columns( N Cols( dt ) );

//loop to replace names starting at the end of the table
For( c = N Cols( dt ), c > 0, c--,
	Column( c ) << Set Name( colNames[c+1] )
);

 

I hope this helps!

@julian 

 

mlo1
Level IV

Re: How to Skip charater to import column header

Hi @julian 

thank you very much. It's a working solution.

 

jthi
Super User

Re: How to Skip charater to import column header

Here is other option which relies on removing few extra characters and then "opening the file" again by using Char To Blob()

Names Default To Here(1);

txt = Load Text File("$DOWNLOADS/JMPTest.txt");
txt = Substr(txt, 3, - 1); // drop first three characters
dt = Open(
	Char To Blob(txt),
	End Of Field(Spaces, Space, CSV(0))
);
-Jarmo
Jeff_Perkinson
Community Manager Community Manager

Re: How to Skip charater to import column header

If you don't want to script this, it's pretty easy to deal with moving the column names after the table is opened.

 

  1. Select columns 2 through n (i.e., the last column in the table) in the columns list on the left side of the data table, then Ctrl-C or Edit->Copy and you'll copy the column names to the clipboard.
  2. Then, delete the last column of the data table, otherwise you'll end up with a duplicate column name.
  3. Finally, select all the columns the columns list and Ctrl-V or Edit->Paste and you'll paste the column names you just copied.

CopyPasteColumnNames.gif

 

Note that the selection of the columns in the columns list on the left is the important bit. That puts the keyboard focus in that list so that Copy and Paste get the column names and not the data from the data table.

 

-Jeff
hogi
Level XII

Re: How to Skip charater to import column header

@Jeff_Perkinson  's approach is very elegant ...

if you are interested in more such easter eggs in Jmp, you can have a look at this list:
CTRL/Alt/Shift + click/select/double click/right click 

I guess there are hundreds more - just waiting till some user finds them