<?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: column header search and replace in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/column-header-search-and-replace/m-p/374185#M62393</link>
    <description>&lt;P&gt;Hi Sam,&lt;/P&gt;
&lt;P&gt;It seems that the issue is with the direct renaming of the column in the second loop (j) where you are still making substitution.&lt;/P&gt;
&lt;P&gt;One possible solution (shown below) is to modify the list of headers (hl) and then to rename the column after all changes have been made:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Open( "C:\Program Files\SAS\JMP\14\Samples\Data\Big Class.jmp" );
hl = dt &amp;lt;&amp;lt; get column names( string );

sr = List();
sr[1] = "height";									// 
sr[2] = "e";										// Order of replacement strings is critical
sr[3] = "a";										//	

For( i = 1, i &amp;lt;= N Items( hl ), i++,
	For (j = 1, j &amp;lt;= N Items (sr), j++,
		If (contains (hl [i], sr [j]), 
			txt = substitute (hl [i], sr [j], "x"); // Just for clarity: the expression could be wrapped into the next
			Substitute into (hl, hl [i], txt);		// Hold all the changes into the hl list
			)
		);
	Column (dt , i ) &amp;lt;&amp;lt; set name (hl [i]);			// Renames column only after all changes have been made
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I hope it helps.&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;TS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 03 Apr 2021 21:10:36 GMT</pubDate>
    <dc:creator>Thierry_S</dc:creator>
    <dc:date>2021-04-03T21:10:36Z</dc:date>
    <item>
      <title>column header search and replace</title>
      <link>https://community.jmp.com/t5/Discussions/column-header-search-and-replace/m-p/374105#M62381</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can replace the column header name with the exact name using&amp;nbsp;&lt;CODE class=" language-jsl"&gt;:height &amp;lt;&amp;lt; Set Name( "test" );&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I have a list of text I want to replace to "".&lt;/P&gt;&lt;P&gt;How do I proceed with that?&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;"name" "Time" "sex" "height abc weight" "weight xyz" "12 height test"&lt;BR /&gt;KATIE 12 F 59 95 59&lt;BR /&gt;LOUISE 12 F 61 123 61&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Final output:&lt;/P&gt;&lt;P&gt;"name" "Time" "sex" "abc" "xyz" "12 test"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Open( "C:/JSL/BigClass.jmp" );
headerList = dt &amp;lt;&amp;lt; get column names( string );

//:height &amp;lt;&amp;lt; Set Name( "test" );

For( i = 1, i &amp;lt;= N Items( headerList ), i++,
	If( (headerList[i] == "height" || headerList[i] == "weight"), //trying to find any column header has height or weight and replace with ""
		Column( dt, colList[i] ) &amp;lt;&amp;lt; set name( " " ) //above are just two examples, maybe put it in list and loop?
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 22:10:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/column-header-search-and-replace/m-p/374105#M62381</guid>
      <dc:creator>sam_t</dc:creator>
      <dc:date>2023-06-09T22:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: column header search and replace</title>
      <link>https://community.jmp.com/t5/Discussions/column-header-search-and-replace/m-p/374108#M62382</link>
      <description>&lt;P&gt;Hi Sam,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found 2 problems in your script:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You used the concatenate "||" code to represent your "Or" statement (should be "|")&lt;/LI&gt;
&lt;LI&gt;JMP does not allow for column to be named as " ".&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Also, it is usually faster and easier to call the column by number instead of iterating through the Column Name List&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, here is what I came up with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Open( "C:\Program Files\SAS\JMP\14\Samples\Data\Big Class.jmp" );
headerList = dt &amp;lt;&amp;lt; get column names( string );

For( i = 1, i &amp;lt;= N Items( headerList ), i++,
	If( (headerList[i] == "height" | headerList[i] == "weight"), //Fixed the "Or" statement
		Column( dt, i ) &amp;lt;&amp;lt; set name(substitute (headerList [i], "e", "x")) //Used the substitute function as an example, you can replace any string with ""?
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 05:04:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/column-header-search-and-replace/m-p/374108#M62382</guid>
      <dc:creator>Thierry_S</dc:creator>
      <dc:date>2021-04-03T05:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: column header search and replace</title>
      <link>https://community.jmp.com/t5/Discussions/column-header-search-and-replace/m-p/374159#M62386</link>
      <description>&lt;P&gt;I tried to define the the list ahead of time and do double nested loop. It only substitute on&amp;nbsp;&lt;CODE class=" language-jsl"&gt;stringReplace[3].&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;headerList = dt &amp;lt;&amp;lt; get column names( string );
stringReplace = List();
stringReplace[1] = "height";
stringReplace[2] = "e";
stringReplace[3] = "a";

For( i = 1, i &amp;lt;= N Items( headerList ), i++,
	For( j = 1, j &amp;lt;= N Items( stringReplace ), j++,
		Column( dt, i ) &amp;lt;&amp;lt; set name( Substitute(headerList[i], stringReplace[j], "" ) )
	);
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 16:32:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/column-header-search-and-replace/m-p/374159#M62386</guid>
      <dc:creator>sam_t</dc:creator>
      <dc:date>2021-04-03T16:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: column header search and replace</title>
      <link>https://community.jmp.com/t5/Discussions/column-header-search-and-replace/m-p/374185#M62393</link>
      <description>&lt;P&gt;Hi Sam,&lt;/P&gt;
&lt;P&gt;It seems that the issue is with the direct renaming of the column in the second loop (j) where you are still making substitution.&lt;/P&gt;
&lt;P&gt;One possible solution (shown below) is to modify the list of headers (hl) and then to rename the column after all changes have been made:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Open( "C:\Program Files\SAS\JMP\14\Samples\Data\Big Class.jmp" );
hl = dt &amp;lt;&amp;lt; get column names( string );

sr = List();
sr[1] = "height";									// 
sr[2] = "e";										// Order of replacement strings is critical
sr[3] = "a";										//	

For( i = 1, i &amp;lt;= N Items( hl ), i++,
	For (j = 1, j &amp;lt;= N Items (sr), j++,
		If (contains (hl [i], sr [j]), 
			txt = substitute (hl [i], sr [j], "x"); // Just for clarity: the expression could be wrapped into the next
			Substitute into (hl, hl [i], txt);		// Hold all the changes into the hl list
			)
		);
	Column (dt , i ) &amp;lt;&amp;lt; set name (hl [i]);			// Renames column only after all changes have been made
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I hope it helps.&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;TS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 21:10:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/column-header-search-and-replace/m-p/374185#M62393</guid>
      <dc:creator>Thierry_S</dc:creator>
      <dc:date>2021-04-03T21:10:36Z</dc:date>
    </item>
  </channel>
</rss>

