<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Apply script to multiple data tables in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Apply-script-to-multiple-data-tables/m-p/716338#M89844</link>
    <description>&lt;P&gt;Thanks for your reply! I tried your script, but it is only running the table_script function on the last data table that is opened. Do you have any idea what might be the problem? Thank you.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jan 2024 14:38:26 GMT</pubDate>
    <dc:creator>Raquel</dc:creator>
    <dc:date>2024-01-12T14:38:26Z</dc:date>
    <item>
      <title>Apply script to multiple data tables</title>
      <link>https://community.jmp.com/t5/Discussions/Apply-script-to-multiple-data-tables/m-p/714406#M89771</link>
      <description>&lt;P&gt;I have a script where I open a txt file in JMP as a data table and then&amp;nbsp;move the column names listed in row 7 to the column headers. How can I apply this to multiple data tables? My current script is not working. I have JMP16. Thanks.&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt_list = Multiple File Import(); //additional known text here to open files

table_script = expr( 
//Move the column names listed in row 7 to the column headers
dt = Current Data Table();
dt &amp;lt;&amp;lt; clear select;
dt &amp;lt;&amp;lt; Clear Column Selection();
lastcol = N Col( dt );
header = 7;
  For( i = 1, i &amp;lt;= lastcol, i++,
   Column( i ) &amp;lt;&amp;lt; set Name( Column(i)[header] )
  );
 );
 
Eval( 
	Eval Expr(
		For Each( {value, index},
			Expr( dt_list[index] &amp;lt;&amp;lt; table_script )
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 09 Jan 2024 18:26:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Apply-script-to-multiple-data-tables/m-p/714406#M89771</guid>
      <dc:creator>Raquel</dc:creator>
      <dc:date>2024-01-09T18:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: Apply script to multiple data tables</title>
      <link>https://community.jmp.com/t5/Discussions/Apply-script-to-multiple-data-tables/m-p/714428#M89774</link>
      <description>&lt;P&gt;Here is how I would set it up&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt_list = Multiple File Import();

table_script = Function( {dt},
	{defaultlocal}, 
//Move the column names listed in row 7 to the column headers

	dt &amp;lt;&amp;lt; clear select;
	dt &amp;lt;&amp;lt; Clear Column Selection();
	lastcol = N Col( dt );
	header = 7;
	For( i = 1, i &amp;lt;= lastcol, i++,
		Column( i ) &amp;lt;&amp;lt; set Name( Column( i )[header] )
	);
);
 
For Each( {value}, dt_list, table_script( value ) );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jan 2024 18:52:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Apply-script-to-multiple-data-tables/m-p/714428#M89774</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-01-09T18:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: Apply script to multiple data tables</title>
      <link>https://community.jmp.com/t5/Discussions/Apply-script-to-multiple-data-tables/m-p/716338#M89844</link>
      <description>&lt;P&gt;Thanks for your reply! I tried your script, but it is only running the table_script function on the last data table that is opened. Do you have any idea what might be the problem? Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 14:38:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Apply-script-to-multiple-data-tables/m-p/716338#M89844</guid>
      <dc:creator>Raquel</dc:creator>
      <dc:date>2024-01-12T14:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: Apply script to multiple data tables</title>
      <link>https://community.jmp.com/t5/Discussions/Apply-script-to-multiple-data-tables/m-p/716398#M89848</link>
      <description>&lt;P&gt;I replicated the finding that you indicated, and I was not able to correct the issue using the approach that I was taking.&amp;nbsp; So I went back to your original code, and simplified the approach and was successful in running a complete example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

rc = Create Directory( "$TEMP/sub1" );

dt = Open( "$SAMPLE_DATA/big class.jmp" );
Close( dt, save( "$TEMP/sub1/MFI big class.jmp" ) );
dt = Open( "$SAMPLE_DATA/body fat.jmp" );
Close( dt, save( "$TEMP/sub1/MFI body fat.jmp" ) );
dt = Open( "$SAMPLE_DATA/candy bars.jmp" );
Close( dt, save( "$TEMP/sub1/MFI candy bars.jmp" ) );

Show( Files In Directory( "$TEMP/sub1" ) );

dt_list = Multiple File Import(
	&amp;lt;&amp;lt;Set Folder( "$TEMP\sub1\" ),
	&amp;lt;&amp;lt;Set Stack Mode( "Table Per File" )
) &amp;lt;&amp;lt; Import Data;


table_script = Expr( 
//Move the column names listed in row 7 to the column headers
	dt = Current Data Table();
	dt &amp;lt;&amp;lt; clear select;
	dt &amp;lt;&amp;lt; Clear Column Selection();
	lastcol = N Col( dt );
	header = 7;
	For( i = 1, i &amp;lt;= lastcol, i++,
		Column( i ) &amp;lt;&amp;lt; set Name( (Column( i ) &amp;lt;&amp;lt; get name) || Char( header ) )
	);
);
 
For Each( {table}, dt_list,
	Current Data Table( table );
	table_script;
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jan 2024 16:11:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Apply-script-to-multiple-data-tables/m-p/716398#M89848</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-01-12T16:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: Apply script to multiple data tables</title>
      <link>https://community.jmp.com/t5/Discussions/Apply-script-to-multiple-data-tables/m-p/717393#M89913</link>
      <description>&lt;P&gt;Thank you so much! Your new script worked to make edits to all data tables that were opened. However, I found that my script was not operating as intended and was attaching a "7" to all column headers instead of moving row 7 to being the column headers. It previously worked on a single data table, but in this case, I needed to change my code to actually read the table value in the specified location. Here is my working code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt_list = Multiple File Import();

table_script = Expr( 
//Move the column names listed in row 7 to the column headers
	dt = Current Data Table();
	dt &amp;lt;&amp;lt; clear select;
	dt &amp;lt;&amp;lt; Clear Column Selection();
	lastcol = N Col( dt );
	header = 7;
	For( i = 1, i &amp;lt;= lastcol, i++,
	tableVal = Column( Current Data Table(), i)[ header ];
		Column( i ) &amp;lt;&amp;lt; set Name( tableVal )
	);
);
 
For Each( {table}, dt_list,
	Current Data Table( table );
	table_script;
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 19:55:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Apply-script-to-multiple-data-tables/m-p/717393#M89913</guid>
      <dc:creator>Raquel</dc:creator>
      <dc:date>2024-01-16T19:55:44Z</dc:date>
    </item>
  </channel>
</rss>

