<?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 Script for multiple data tables/ Workflow in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Script-for-multiple-data-tables-Workflow/m-p/724406#M90666</link>
    <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am relatively new to JMP and especially to scripting in JSL. I am looking for a way to apply a existing script to all currently open data tables (imported via multiple files import). Even though I researched through the abundance of community threads about this topic, I was not able to piece together a working solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Okay, so I have the following working JSL code (note: embedded in a workflow, if relevant):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Specify the dataset and the suffix to search for in column headers
dt = Current Data Table();
// Define suffix of interest for replacement
targetSuffix = "TimeAbs"; 

// Get list of column names from the current data table
colNames = dt &amp;lt;&amp;lt; Get Column Names( "string" );

// Loop through all column names and check if the target suffix is present
For( i = 1, i &amp;lt;= N Items( colNames ), i++,
    If( Contains( colNames[i], targetSuffix ),
        // If the target suffix is found, change the column header to "Date"
        Column( dt, colNames[i] ) &amp;lt;&amp;lt; Set Name( "Date" )
    )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The current function of the workflow is the replacement of a column name in the currently open data table, however this name can vary between files, which is why I decided to only search for a fixed suffix.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would now like to expand this script to apply to multiple data tables I have currently open. I have seen solutions on similar tasks based on For or For Each Loops and also with table scripts, but as I said I am quite new to JSL and failed to succeed as of yet.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Furthermore, this needs to be quite generic, because the file names and column names can vary quite drastically.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ultimate goal is then to concatenate these table, but might be out of scope for a single question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for any advice or ideas&lt;/P&gt;</description>
    <pubDate>Thu, 15 Feb 2024 13:47:34 GMT</pubDate>
    <dc:creator>Gab_K</dc:creator>
    <dc:date>2024-02-15T13:47:34Z</dc:date>
    <item>
      <title>Script for multiple data tables/ Workflow</title>
      <link>https://community.jmp.com/t5/Discussions/Script-for-multiple-data-tables-Workflow/m-p/724406#M90666</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am relatively new to JMP and especially to scripting in JSL. I am looking for a way to apply a existing script to all currently open data tables (imported via multiple files import). Even though I researched through the abundance of community threads about this topic, I was not able to piece together a working solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Okay, so I have the following working JSL code (note: embedded in a workflow, if relevant):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Specify the dataset and the suffix to search for in column headers
dt = Current Data Table();
// Define suffix of interest for replacement
targetSuffix = "TimeAbs"; 

// Get list of column names from the current data table
colNames = dt &amp;lt;&amp;lt; Get Column Names( "string" );

// Loop through all column names and check if the target suffix is present
For( i = 1, i &amp;lt;= N Items( colNames ), i++,
    If( Contains( colNames[i], targetSuffix ),
        // If the target suffix is found, change the column header to "Date"
        Column( dt, colNames[i] ) &amp;lt;&amp;lt; Set Name( "Date" )
    )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The current function of the workflow is the replacement of a column name in the currently open data table, however this name can vary between files, which is why I decided to only search for a fixed suffix.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would now like to expand this script to apply to multiple data tables I have currently open. I have seen solutions on similar tasks based on For or For Each Loops and also with table scripts, but as I said I am quite new to JSL and failed to succeed as of yet.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Furthermore, this needs to be quite generic, because the file names and column names can vary quite drastically.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ultimate goal is then to concatenate these table, but might be out of scope for a single question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for any advice or ideas&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2024 13:47:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-for-multiple-data-tables-Workflow/m-p/724406#M90666</guid>
      <dc:creator>Gab_K</dc:creator>
      <dc:date>2024-02-15T13:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: Script for multiple data tables/ Workflow</title>
      <link>https://community.jmp.com/t5/Discussions/Script-for-multiple-data-tables-Workflow/m-p/724415#M90671</link>
      <description>&lt;P&gt;You can get list of table with Get Data Table List() and then loop over that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

targetSuffix = "TimeAbs";

For Each({dt_cur}, Get Data Table List(),
	colNames = dt_cur &amp;lt;&amp;lt; Get Column Names("String");
	For Each({colname}, colnames,
		If(Contains(colname, targetSuffix),
			Column(dt_cur, colname) &amp;lt;&amp;lt; Set Name("Date")
		)
	);	
);

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also convert the inside of your loop into a function or expression&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

change_table_name = function({dt, targetsuffix = "TimeAbs", newname = "Date"}, {Default Local},
	colnames = dt &amp;lt;&amp;lt; Get Column Names("String");
	For Each({colname}, colnames,
		If(Contains(colname, targetsuffix),
			Column(dt, colname) &amp;lt;&amp;lt; Set Name(newname)
		)
	);
);

For Each({dt_cur}, Get Data Table List(),
	change_table_name(dt_cur);
);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Feb 2024 15:30:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-for-multiple-data-tables-Workflow/m-p/724415#M90671</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-02-15T15:30:05Z</dc:date>
    </item>
  </channel>
</rss>

