<?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 Find string in column, rename the column and add new column in JSL in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Find-string-in-column-rename-the-column-and-add-new-column-in/m-p/399120#M64991</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table like below and want to find the String "Z", "A" and "B" in the columns and rename it to "Z_A" and "Z_B".&lt;/P&gt;&lt;P&gt;After that, I want to add a column after X_loc and Y_loc which converts them to mm. The formula that I want to use is (X_Loc / 1000).&lt;/P&gt;&lt;P&gt;Can anyone guide me on how to do the scripting for this?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="achid03_0-1625641187776.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/34005i99EACC2134D4F808/image-size/medium?v=v2&amp;amp;px=400" role="button" title="achid03_0-1625641187776.png" alt="achid03_0-1625641187776.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 19:51:46 GMT</pubDate>
    <dc:creator>achid03</dc:creator>
    <dc:date>2023-06-09T19:51:46Z</dc:date>
    <item>
      <title>Find string in column, rename the column and add new column in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Find-string-in-column-rename-the-column-and-add-new-column-in/m-p/399120#M64991</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table like below and want to find the String "Z", "A" and "B" in the columns and rename it to "Z_A" and "Z_B".&lt;/P&gt;&lt;P&gt;After that, I want to add a column after X_loc and Y_loc which converts them to mm. The formula that I want to use is (X_Loc / 1000).&lt;/P&gt;&lt;P&gt;Can anyone guide me on how to do the scripting for this?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="achid03_0-1625641187776.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/34005i99EACC2134D4F808/image-size/medium?v=v2&amp;amp;px=400" role="button" title="achid03_0-1625641187776.png" alt="achid03_0-1625641187776.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 19:51:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Find-string-in-column-rename-the-column-and-add-new-column-in/m-p/399120#M64991</guid>
      <dc:creator>achid03</dc:creator>
      <dc:date>2023-06-09T19:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: Find string in column, rename the column and add new column in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Find-string-in-column-rename-the-column-and-add-new-column-in/m-p/399202#M65001</link>
      <description>&lt;OL&gt;
&lt;LI&gt;You need to read the Discovering JMP document, and the Scripting Guide!&lt;/LI&gt;
&lt;LI&gt;You need to attempt to solve the problem first.&amp;nbsp; One learns by making mistakes and figuring out what the problem is&lt;/LI&gt;
&lt;LI&gt;When you fail at solving the problem, the Discussion Community is there to help.&lt;/LI&gt;
&lt;LI&gt;Below is a script that if you have setup your data table correctly, should show you one way to solve the problem
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

// Create a sample table
dt = New Table( "Example",
	Add Rows( 3 ),
	New Column( "ID", Character, "Nominal", Set Values( {"#1", "#2", "#3"} ) ),
	New Column( "X_loc", Set Values( [2, 3, 4] ) ),
	New Column( "Y_loc", Set Values( [2, 2, 4] ) ),
	New Column( "Z_Surce_Column_A", Set Values( [4, 5, -4] ), Set Display Width( 118 ) ),
	New Column( "Z_Source_Column_B", Set Values( [-4, -10, 1] ), Set Display Width( 133 ) )
);

// Wait 5 seconds so you can see the beginning table
wait(5);

// Loop across the columns to find the ones to change
For( i = 1, i &amp;lt;= N Cols( dt ), i++,
	If(
		Contains( Column( dt, i ) &amp;lt;&amp;lt; get name, "Z" ) &amp;amp; Contains( Column( dt, i ) &amp;lt;&amp;lt; get name, "A" ),
			Column( dt, i ) &amp;lt;&amp;lt; set name( "Z_A" ),
		Contains( Column( dt, i ) &amp;lt;&amp;lt; get name, "Z" ) &amp;amp; Contains( Column( dt, i ) &amp;lt;&amp;lt; get name, "B" ),
			Column( dt, i ) &amp;lt;&amp;lt; set name( "Z_B" )
	)
);

// Create the new column and move it to where it is to be located
dt &amp;lt;&amp;lt; New Column("The New Column", formula(:X_loc/1000));
dt &amp;lt;&amp;lt; go to(:The New Column );
dt &amp;lt;&amp;lt; Move Selected Columns(After(:Y_loc));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need to study the script and learn how it works.&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 07 Jul 2021 12:10:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Find-string-in-column-rename-the-column-and-add-new-column-in/m-p/399202#M65001</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-07-07T12:10:24Z</dc:date>
    </item>
  </channel>
</rss>

