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
UserID16644
Level V

Extract file name from data table

Hi all,

I need to open data tables where the file names are being extracted from my main table and after opening the data table, it will merge it into one data table. Also, col2 have the same values inside dt.

It should look like this:

C:\Desktop\Name_Ana_Gender_Female.jmp

C:\Desktop\Name_Grace_Gender_Female.jmp

 

I have this code but it only opens one data table 

dt = Data Table( "sample_table" );

col_name=associative array(column(dt, "name" ) <<get values) <<get keys;
col_gender=associative array(column(dt, "gender" ) <<get values) <<get keys;

file_list = N Items( col_name );
file_path = "C:\Desktop";
For( i = 1, i < file_list, i++,
dt1 = Open( file_path || "Name_" || char(col_name[i]) || " _Gender_" || char(col_gender[1]) || ".jmp",
//merge the two opened table
	)
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Extract file name from data table

  1. Please take the time to go through the Discovering JMP and Using JMP documentation.  They will help you learn about the fundamental features of JMP.  Then, you will be able to use those features and then let JMP provide you with the JSL to create the scripts.
  2. There are several previous Discussion Tracks on the topic of reading in multiple data tables and then putting them together.  Please start searching them.  You will be able to solve your problems much faster.
  3. Here is a possible solution to your scripting needs.  It is untested.
    dt = Data Table( "sample_table" );
    
    col_name = dt:names << get values;
    col_gender = dt:gender << get values;
    
    file_list = N Items( col_name );
    file_path = "C:\Desktop\";
    
    dtFinal = New Table( "Final Table" );
    
    For( i = 1, i <= file_list, i++,
    	dt1 = Open( file_path || "Name_" || Char( col_name[i] ) || " _Gender_" || Char( col_gender[1] ) || ".jmp" );
    	dtFinal << concatenate( dt1, append to first table( 1 ) );
    	Close( dt1, nosave );
    );
     
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Extract file name from data table

  1. Please take the time to go through the Discovering JMP and Using JMP documentation.  They will help you learn about the fundamental features of JMP.  Then, you will be able to use those features and then let JMP provide you with the JSL to create the scripts.
  2. There are several previous Discussion Tracks on the topic of reading in multiple data tables and then putting them together.  Please start searching them.  You will be able to solve your problems much faster.
  3. Here is a possible solution to your scripting needs.  It is untested.
    dt = Data Table( "sample_table" );
    
    col_name = dt:names << get values;
    col_gender = dt:gender << get values;
    
    file_list = N Items( col_name );
    file_path = "C:\Desktop\";
    
    dtFinal = New Table( "Final Table" );
    
    For( i = 1, i <= file_list, i++,
    	dt1 = Open( file_path || "Name_" || Char( col_name[i] ) || " _Gender_" || Char( col_gender[1] ) || ".jmp" );
    	dtFinal << concatenate( dt1, append to first table( 1 ) );
    	Close( dt1, nosave );
    );
     
Jim
David_Burnham
Super User (Alumni)

Re: Extract file name from data table

If col_name only contains one item then you would expect your code to open only one table.  So why not start by looking at the contents of that list (use the show function).  How many items does it contain?  Next look at your loop - is it really looping over each item in the list?  Perhaps you need "<=" instead of "<".  I would also suggest that 

 

1. you use meaningful names.  I would expect file_list to be a list of files and col_name to be the name of a column.

2. don't put tons of logic into a single line, it's not clever - it  just makes it impossible to debug.  

-Dave