<?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: Recode columns containing character value at the end of a column in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Recode-columns-containing-character-value-at-the-end-of-a-column/m-p/397829#M64853</link>
    <description>&lt;P&gt;For this I would go with regex. I liked this at onepoint to get going with regex at least on some level: &lt;A href="https://regexone.com/" target="_self"&gt;regexone&lt;/A&gt; also check out &lt;A href="https://www.jmp.com/support/help/en/15.2/#page/jmp/character-functions-2.shtml?os=win&amp;amp;source=application&amp;amp;utm_source=helpmenu&amp;amp;utm_medium=application#ww4813286" target="_self"&gt;JMP Character Functions - Regex&lt;/A&gt; and Regex from scripting index.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example with two possible ways to remove end characters using Regex in JMP (they can be easily modified to support non-capital letters also):&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 = New Table("Untitled 3",
	Add Rows(5),
	Compress File When Saved(1),
	New Column("ID",
		Character,
		"Nominal",
		Set Values(
			{"ABC001235G", "ABC001234", "ABC001235", "ABC001234D", "ABC001234F"}
		)
	)
);


dt &amp;lt;&amp;lt; New Column("Regex1", Character, Nominal, Formula(Regex(:ID, "^[A-Z]+(\d+)")));
dt &amp;lt;&amp;lt; New Column("Regex2", Character, Nominal, Formula(Regex(:ID, "[A-Z]*$", "", GLOBALREPLACE);));


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Depending on the use case choose one (easy to test with the example code how they work with different strings):&lt;/P&gt;&lt;P&gt;First one will match 1 or more capital characters from the start of the string followed by any amount of digits (so it will ignore anything after the digits).&lt;/P&gt;&lt;P&gt;Second one will match zero or more capital characters from the end of string and replace them with empty string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Jul 2021 07:14:19 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2021-07-02T07:14:19Z</dc:date>
    <item>
      <title>Recode columns containing character value at the end of a column</title>
      <link>https://community.jmp.com/t5/Discussions/Recode-columns-containing-character-value-at-the-end-of-a-column/m-p/397737#M64848</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table like&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Column2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC001235G&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC001234&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC001235&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC001234D&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC001234F&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to recode the ID column such that all my values like 'ABC001234D' and 'ABC001234F' become 'ABC001234' - basically I want to drop that last letter in the statement. However, I cannot do this through manual process. There are too many rows to do and I couldn't possibly write it manually for each ID that is possible to be used in the script. Looking for a way to do this through scripting. Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:33:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Recode-columns-containing-character-value-at-the-end-of-a-column/m-p/397737#M64848</guid>
      <dc:creator>saneal</dc:creator>
      <dc:date>2023-06-10T23:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Recode columns containing character value at the end of a column</title>
      <link>https://community.jmp.com/t5/Discussions/Recode-columns-containing-character-value-at-the-end-of-a-column/m-p/397756#M64849</link>
      <description>&lt;P&gt;Hi, saneal!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a formula that might help you, but you will have to make some assumptions about the naming conventions and accuracy of the ID variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your ID values consistently have 3 characters at the beginning, you could make a new column and use this formula:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Substr( :ID, 1, 3 ) || Regex( :ID, "\d+" )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This formula will allow for inconsistent length of numeric values.&amp;nbsp; It's not too hard to adapt the formula for having inconsistent numbers of characters at the beginning of the ID values, either.&amp;nbsp; But if someone ever mistypes the ID as 0 (the number) instead of O (the letter), or any other certain typographical errors, you may get unexpected results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good luck,&lt;/P&gt;&lt;P&gt;Kevin&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 22:35:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Recode-columns-containing-character-value-at-the-end-of-a-column/m-p/397756#M64849</guid>
      <dc:creator>Kevin_Anderson</dc:creator>
      <dc:date>2021-07-01T22:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Recode columns containing character value at the end of a column</title>
      <link>https://community.jmp.com/t5/Discussions/Recode-columns-containing-character-value-at-the-end-of-a-column/m-p/397772#M64850</link>
      <description>&lt;P&gt;You can do this with the following formula:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;val = Reverse( :ID );
While( Is Missing( Num( Substr( val, 1, 1 ) ) ),
	val = Substr( val, 2 )
);
Reverse( val );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This will remove all trailing non-numeric values&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jul 2021 00:28:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Recode-columns-containing-character-value-at-the-end-of-a-column/m-p/397772#M64850</guid>
      <dc:creator>ErraticAttack</dc:creator>
      <dc:date>2021-07-02T00:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Recode columns containing character value at the end of a column</title>
      <link>https://community.jmp.com/t5/Discussions/Recode-columns-containing-character-value-at-the-end-of-a-column/m-p/397829#M64853</link>
      <description>&lt;P&gt;For this I would go with regex. I liked this at onepoint to get going with regex at least on some level: &lt;A href="https://regexone.com/" target="_self"&gt;regexone&lt;/A&gt; also check out &lt;A href="https://www.jmp.com/support/help/en/15.2/#page/jmp/character-functions-2.shtml?os=win&amp;amp;source=application&amp;amp;utm_source=helpmenu&amp;amp;utm_medium=application#ww4813286" target="_self"&gt;JMP Character Functions - Regex&lt;/A&gt; and Regex from scripting index.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example with two possible ways to remove end characters using Regex in JMP (they can be easily modified to support non-capital letters also):&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 = New Table("Untitled 3",
	Add Rows(5),
	Compress File When Saved(1),
	New Column("ID",
		Character,
		"Nominal",
		Set Values(
			{"ABC001235G", "ABC001234", "ABC001235", "ABC001234D", "ABC001234F"}
		)
	)
);


dt &amp;lt;&amp;lt; New Column("Regex1", Character, Nominal, Formula(Regex(:ID, "^[A-Z]+(\d+)")));
dt &amp;lt;&amp;lt; New Column("Regex2", Character, Nominal, Formula(Regex(:ID, "[A-Z]*$", "", GLOBALREPLACE);));


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Depending on the use case choose one (easy to test with the example code how they work with different strings):&lt;/P&gt;&lt;P&gt;First one will match 1 or more capital characters from the start of the string followed by any amount of digits (so it will ignore anything after the digits).&lt;/P&gt;&lt;P&gt;Second one will match zero or more capital characters from the end of string and replace them with empty string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jul 2021 07:14:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Recode-columns-containing-character-value-at-the-end-of-a-column/m-p/397829#M64853</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-07-02T07:14:19Z</dc:date>
    </item>
  </channel>
</rss>

