<?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: How do I code find &amp;amp; replace in JSL, to remove text from a column &amp;amp; convert to number format. in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-do-I-code-find-amp-replace-in-JSL-to-remove-text-from-a/m-p/221082#M44121</link>
    <description>&lt;P&gt;Hi Jim, your code didn't quite work, and I couldn't figure out why. I've uploaded a screenshot of JMP's debugger with the error message, and a subset of my data if you'd like to continue tackling this. I'd be very interested in this alternative solution!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2019-08-08 13.48.41.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/18733i3E9AE680AED058B3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2019-08-08 13.48.41.png" alt="Screenshot 2019-08-08 13.48.41.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Aug 2019 12:46:56 GMT</pubDate>
    <dc:creator>jpmontagne</dc:creator>
    <dc:date>2019-08-09T12:46:56Z</dc:date>
    <item>
      <title>How do I code find &amp; replace in JSL, to remove text from a column &amp; convert to number format.</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-code-find-amp-replace-in-JSL-to-remove-text-from-a/m-p/221050#M44113</link>
      <description>&lt;P&gt;Hello JMP community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once a week, I import .txt data with a battery voltage column (named "V1") where row values can be "3.45V",&amp;nbsp;"3.34V",&amp;nbsp;"3.12V",&amp;nbsp;"3.23V", etc. I use Find &amp;amp; Replace manually to remove the letter "V" from the data, then manually change the data type from Character to Numeric. I suppose I don't quite understand how to include substitute() or mumger() in my scripts because&amp;nbsp;I've tried &amp;amp; failed to create a working JSL for this simple task.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2019 19:50:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-code-find-amp-replace-in-JSL-to-remove-text-from-a/m-p/221050#M44113</guid>
      <dc:creator>jpmontagne</dc:creator>
      <dc:date>2019-08-08T19:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I code find &amp; replace in JSL, to remove text from a column &amp; convert to number format.</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-code-find-amp-replace-in-JSL-to-remove-text-from-a/m-p/221063#M44115</link>
      <description>&lt;P&gt;I've always been a big fan of producing the solution interactively first, then script. I know it is not always possible, but you can get close.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Opening the text file gives this script (for my example, of course) found in the Source script with the JMP table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Open(
	"C:\Testing.txt",
	columns( New Column( "V1", Character, "Nominal" ) ),
	Import Settings(
		End Of Line( CRLF, CR, LF ),
		End Of Field( Tab, Comma, CSV( 1 ) ),
		Strip Quotes( 1 ),
		Use Apostrophe as Quotation Mark( 0 ),
		Use Regional Settings( 0 ),
		Scan Whole File( 1 ),
		Treat empty columns as numeric( 0 ),
		CompressNumericColumns( 0 ),
		CompressCharacterColumns( 0 ),
		CompressAllowListCheck( 0 ),
		Labels( 1 ),
		Column Names Start( 1 ),
		Data Starts( 2 ),
		Lines To Read( "All" ),
		Year Rule( "20xx" )
	)
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can modify as needed for your specific case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now for removing the V and converting to numeric, I would create a second column for that. This allows for error checking in case the voltage format changes, for some reason. Plus, it gives better data traceability. I created a column with this formula:&amp;nbsp;Num( Word( 1, :V1, "V" ) ). I then looked at the "Copy Table Script" found in the table panel and pulled out the related part of the script to create the new column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In JSL that would be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Column( "Numeric V1",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( Num( Word( 1, :V1, "V" ) ) )
	)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Putting the two together should be your script.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2019 20:17:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-code-find-amp-replace-in-JSL-to-remove-text-from-a/m-p/221063#M44115</guid>
      <dc:creator>Dan_Obermiller</dc:creator>
      <dc:date>2019-08-08T20:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I code find &amp; replace in JSL, to remove text from a column &amp; convert to number format.</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-code-find-amp-replace-in-JSL-to-remove-text-from-a/m-p/221065#M44117</link>
      <description>&lt;P&gt;See if something like this will work......it has not been fully tested, but it should be close to working&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

colNames = dt &amp;lt;&amp;lt; get column names( string, character );

For( theCol = 1, thecol &amp;lt;= N Items( colNames ), theCol++,
	For( theRow = 1, theRow &amp;lt;= N Rows( dt ), theRow++,
		If( Right( Column( dt, theCol )[theRow], 1 ) == "V",
			Column( dt, theCol )[theRow] = Substr(
				Column( dt, theCol )[theRow],
				1,
				Length( Column( dt, theCol )[theRow] ) - 1
			)
		)
	)
);
If( Is Missing( Num( Column( dt, theCol )[1] ) ) == 0,
	Column( dt, theCol ) &amp;lt;&amp;lt; data type( numeric ) &amp;lt;&amp;lt; modeling type( continuous )
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Aug 2019 20:10:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-code-find-amp-replace-in-JSL-to-remove-text-from-a/m-p/221065#M44117</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-08-08T20:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I code find &amp; replace in JSL, to remove text from a column &amp; convert to number format.</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-code-find-amp-replace-in-JSL-to-remove-text-from-a/m-p/221081#M44120</link>
      <description>&lt;P&gt;Thanks, Dan,&lt;BR /&gt;&lt;BR /&gt;I was able to fit this into my workflow as:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
:Name( "V1" ) &amp;lt;&amp;lt; Set Name( "orig V1" );
New Column( "V1",
	Numeric,
	"Continuous",
	Format( "Fixed Dec", 6, 2 ),
	Formula( Num( Word( 1, :orig V1, "V" ) ) )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I appreciate the quick response!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 12:46:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-code-find-amp-replace-in-JSL-to-remove-text-from-a/m-p/221081#M44120</guid>
      <dc:creator>jpmontagne</dc:creator>
      <dc:date>2019-08-09T12:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do I code find &amp; replace in JSL, to remove text from a column &amp; convert to number format.</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-code-find-amp-replace-in-JSL-to-remove-text-from-a/m-p/221082#M44121</link>
      <description>&lt;P&gt;Hi Jim, your code didn't quite work, and I couldn't figure out why. I've uploaded a screenshot of JMP's debugger with the error message, and a subset of my data if you'd like to continue tackling this. I'd be very interested in this alternative solution!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2019-08-08 13.48.41.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/18733i3E9AE680AED058B3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2019-08-08 13.48.41.png" alt="Screenshot 2019-08-08 13.48.41.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 12:46:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-code-find-amp-replace-in-JSL-to-remove-text-from-a/m-p/221082#M44121</guid>
      <dc:creator>jpmontagne</dc:creator>
      <dc:date>2019-08-09T12:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I code find &amp; replace in JSL, to remove text from a column &amp; convert to number format.</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-code-find-amp-replace-in-JSL-to-remove-text-from-a/m-p/221097#M44125</link>
      <description>&lt;P&gt;I did find a logic error in my code.&amp;nbsp; Below is an example data table with a small script that converts the values in place.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = New Table( "Example",
	add rows( 100 ),
	New Column( "col1", character, formula( Char( Random Integer( 78, 100 ) ) || "V" ) ),
	New Column( "col2", character, formula( Char( Random Integer( 78, 100 ) ) || "V" ) )
);
dt&amp;lt;&amp;lt;run formulas;
dt:col1 &amp;lt;&amp;lt; delete property( "formula" );
dt:col2 &amp;lt;&amp;lt; delete property( "formula" );


colNames = dt &amp;lt;&amp;lt; get column names( string, character );

For( theCol = 1, thecol &amp;lt;= N Items( colNames ), theCol++,
	For( theRow = 1, theRow &amp;lt;= N Rows( dt ), theRow++,
		If( Right( Column( dt, theCol )[theRow], 1 ) == "V",
			Column( dt, theCol )[theRow] = Substr(
				Column( dt, theCol )[theRow],
				1,
				Length( Column( dt, theCol )[theRow] ) - 1
			)
		)
	);

	If( Is Missing( Num( Column( dt, theCol )[1] ) ) == 0,
		Column( dt, theCol ) &amp;lt;&amp;lt; data type( numeric ) &amp;lt;&amp;lt; modeling type( continuous )
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Aug 2019 01:24:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-code-find-amp-replace-in-JSL-to-remove-text-from-a/m-p/221097#M44125</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-08-09T01:24:07Z</dc:date>
    </item>
  </channel>
</rss>

