<?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: Loop for opening files, changing a column name and saving in the original format in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Loop-for-opening-files-changing-a-column-name-and-saving-in-the/m-p/282363#M54633</link>
    <description>&lt;P&gt;1) reformat your JSL using the editor right-click popup. You'll be able to see the nesting better.&lt;/P&gt;&lt;P&gt;2) you are reusing the i variable in the inner loop. That's causing the loop.&lt;/P&gt;&lt;P&gt;3) remove the try() wrapper, or make it do something when it catches an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jul 2020 00:59:01 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2020-07-28T00:59:01Z</dc:date>
    <item>
      <title>Loop for opening files, changing a column name and saving in the original format</title>
      <link>https://community.jmp.com/t5/Discussions/Loop-for-opening-files-changing-a-column-name-and-saving-in-the/m-p/282353#M54631</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried to assemble a script for opening a series of files (.dx) and changing the text from one of the columns on each file. I manage to make it work for one or two files individually but if I try a set of four an infinite loop begins. Can anybody please help? There is a chance that the issue is with the files but I would like to vet the script first since I'm a novice at jsl. Ideally, I would like to save the files not as jmp but as dx also.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Files = Pick File( "Select File(s)", "G:\Retention Compliant\Research\Analytical\Projects\IR database", {"All Files|*"}, 1, 0, "", "multiple" );
For( i = 1, i &amp;lt;= N Items( Files ), i++,
	Try( dt = Open( Files[i], "text" ) );
	wait( 0 );
For( n = 1, n &amp;lt;= N Items (Files), n++, 
colList = dt &amp;lt;&amp;lt; get column names( character, string );
For( i = 1, i &amp;lt;= N Items( colList ), i++,
	selRows = dt &amp;lt;&amp;lt; get rows where(
		Column( dt, colList[i] )[Row()] == "##YUNITS= % Transmittance" | Column( dt, colList[i] )[Row()] == "##YUNITS= % T"
	);
	If( N Rows( selRows ) &amp;gt; 0,
		Column( dt, colList[i] )[selRows] = "##YUNITS= % T";
	);
);
) );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 23:33:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Loop-for-opening-files-changing-a-column-name-and-saving-in-the/m-p/282353#M54631</guid>
      <dc:creator>vmontes</dc:creator>
      <dc:date>2023-06-09T23:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: Loop for opening files, changing a column name and saving in the original format</title>
      <link>https://community.jmp.com/t5/Discussions/Loop-for-opening-files-changing-a-column-name-and-saving-in-the/m-p/282363#M54633</link>
      <description>&lt;P&gt;1) reformat your JSL using the editor right-click popup. You'll be able to see the nesting better.&lt;/P&gt;&lt;P&gt;2) you are reusing the i variable in the inner loop. That's causing the loop.&lt;/P&gt;&lt;P&gt;3) remove the try() wrapper, or make it do something when it catches an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 00:59:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Loop-for-opening-files-changing-a-column-name-and-saving-in-the/m-p/282363#M54633</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2020-07-28T00:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: Loop for opening files, changing a column name and saving in the original format</title>
      <link>https://community.jmp.com/t5/Discussions/Loop-for-opening-files-changing-a-column-name-and-saving-in-the/m-p/282370#M54635</link>
      <description>&lt;P&gt;Thanks Craige, it works now with all files and no errors! Any ideas how to save in the original format (.dx) and preferably preserving the file name?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 01:13:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Loop-for-opening-files-changing-a-column-name-and-saving-in-the/m-p/282370#M54635</guid>
      <dc:creator>vmontes</dc:creator>
      <dc:date>2020-07-28T01:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: Loop for opening files, changing a column name and saving in the original format</title>
      <link>https://community.jmp.com/t5/Discussions/Loop-for-opening-files-changing-a-column-name-and-saving-in-the/m-p/282373#M54636</link>
      <description>&lt;P&gt;Not sure what dx is, but you can save with .csv extension and probably be close.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 01:29:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Loop-for-opening-files-changing-a-column-name-and-saving-in-the/m-p/282373#M54636</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2020-07-28T01:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Loop for opening files, changing a column name and saving in the original format</title>
      <link>https://community.jmp.com/t5/Discussions/Loop-for-opening-files-changing-a-column-name-and-saving-in-the/m-p/282378#M54637</link>
      <description>&lt;P&gt;I have annotated the script below with the issues I found.&amp;nbsp; I am surprised you can read in a .dx file.&amp;nbsp; JMP certainly does not support the writing out of .dx files(as far as I know).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Files = Pick File(
	"Select File(s)",
	"G:\Retention Compliant\Research\Analytical\Projects\IR database",
	{"All Files|*"},
	1,
	0,
	"",
	"multiple"
);
For( i = 1, i &amp;lt;= N Items( Files ), i++,
	// Open one file
	Try( dt = Open( Files[i], "text" ) );
	Wait( 0 );
	// Loop from 1 to the number of files (even though only 1 file has been opened)
	For( n = 1, n &amp;lt;= N Items( Files ), n++,
	    // Here you will be reading the column names in for the first file over and over
		colList = dt &amp;lt;&amp;lt; get column names( character, string );
		// Loop using "i" as the index across all of the columns....in the first file
		// since that is all we have read in.....but since you are using "i", you will
		// be creating an infinate loop, since you are using "i" for the first loop
		// and you will be interferring with the assumed stepping for the outter loop
		For( i = 1, i &amp;lt;= N Items( colList ), i++,
			selRows = dt &amp;lt;&amp;lt; get rows where(
				// You are not in a formula, so the Row() function will not provide a predictable result
				Column( dt, colList[i] )[Row()] == "##YUNITS= % Transmittance" | Column( dt, colList[i] )[Row()] ==
				"##YUNITS= % T"
			);
			If( N Rows( selRows ) &amp;gt; 0,
				Column( dt, colList[i] )[selRows] = "##YUNITS= % T"
			);
		);
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jul 2020 01:49:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Loop-for-opening-files-changing-a-column-name-and-saving-in-the/m-p/282378#M54637</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-07-28T01:49:53Z</dc:date>
    </item>
  </channel>
</rss>

