<?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: Changing the name of every third (n+3) column(s) with specific name; 100+ columns in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Changing-the-name-of-every-third-n-3-column-s-with-specific-name/m-p/613685#M81371</link>
    <description>&lt;P&gt;In your case you can also increment loop in 3s and set three columns at the same time in single loop&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Probe.jmp");
dt &amp;lt;&amp;lt; Ungroup Columns(); // easier to see what is going on if we remove Responses column group

start_col_idx = 4;
colnames = {"px", "num_after_pipe", "value"};

For(i = start_col_idx, i &amp;lt;= N Cols(dt), i = i + 3, // we can increment in 3s
	Try( // lazy try-catch to exit when we cannot set more column names
		Column(i) &amp;lt;&amp;lt; Set Name(colnames[1]);
		Column(i + 1) &amp;lt;&amp;lt; Set Name(colnames[2]);
		Column(i + 2) &amp;lt;&amp;lt; Set Name(colnames[3]);
	,
		show(exception_msg);
		break();
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1679064993074.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/51214i08D8F91C007519DF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1679064993074.png" alt="jthi_0-1679064993074.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Mar 2023 14:57:01 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2023-03-17T14:57:01Z</dc:date>
    <item>
      <title>Changing the name of every third (n+3) column(s) with specific name; 100+ columns</title>
      <link>https://community.jmp.com/t5/Discussions/Changing-the-name-of-every-third-n-3-column-s-with-specific-name/m-p/613275#M81340</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to name a bunch of columns, 100+ of them. I have been doing a bunch of text-to-columns stuff and have many sets of three columns that I want to give the same names to. See below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlphaLion662_3-1678993653136.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/51159iB7F2731F43CC2F57/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlphaLion662_3-1678993653136.png" alt="AlphaLion662_3-1678993653136.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Above shows the columns with names that I want to have, to the left of the red line. It also shows the columns with names that I want to replace. As you can see, I'd like to change every third column, starting at n=1 (or whatever column number I want to start at), and every three columns after that (n+3), rename the column to "pX". The same goes for "num_after_pipe" and "value". All of them up to a point.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working with the following script to rename every set of three columns"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;dt_stack:"Data 1"n&amp;lt;&amp;lt;Set Name("pX");
dt_stack:"Data 2"n&amp;lt;&amp;lt;Set Name("num_after_pipe");
dt_stack:"Data 3"n&amp;lt;&amp;lt;Set Name("value");

dt_stack:"Data 4"n&amp;lt;&amp;lt;Set Name("pX");
dt_stack:"Data 5"n&amp;lt;&amp;lt;Set Name("num_after_pipe");
dt_stack:"Data 6"n&amp;lt;&amp;lt;Set Name("value");

dt_stack:"Data 7"n&amp;lt;&amp;lt;Set Name("pX");
dt_stack:"Data 8"n&amp;lt;&amp;lt;Set Name("num_after_pipe");
.....&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;AlphaLion662&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 16:27:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Changing-the-name-of-every-third-n-3-column-s-with-specific-name/m-p/613275#M81340</guid>
      <dc:creator>AlphaLion662</dc:creator>
      <dc:date>2023-06-08T16:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the name of every third (n+3) column(s) with specific name; 100+ columns</title>
      <link>https://community.jmp.com/t5/Discussions/Changing-the-name-of-every-third-n-3-column-s-with-specific-name/m-p/613297#M81341</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/41286"&gt;@AlphaLion662&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this what you were looking for? Keep in mind, I don't know how you want to modify the column names, so I just added prefixes.&amp;nbsp; You can see the prefixes in the variables first, second, and third.&amp;nbsp; The column renaming happens in the block under the note "&lt;CODE class=" language-jsl"&gt;Col name change here&lt;/CODE&gt;".&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);
clear log();

dt = open( "$SAMPLE_DATA/Arrhythmia.jmp" );

// Gets all column names in a list
allcols = dt &amp;lt;&amp;lt; Get column names();

// Stores the number of columns
numcols = N Items( allcols );

// Some modifier to column names
first = "Tree";
second = "Car";
third = "Star";

For( i = 1, i &amp;lt;= numcols, i++,

	// Temporarly stores the column name for later usage
	temp = column( dt, allcols[i]  ) &amp;lt;&amp;lt; Get Name;
	
	if( 
		
		// First col, then every 3rd col thereafter
		i == 1 | Modulo( i - 1, 3 ) == 0,

			// Col name change here
			col_Name1 = column(dt,i) &amp;lt;&amp;lt; Get Name;
			newname1 = first || "_" || col_Name1;
			eval( column(allcols[i] ) ) &amp;lt;&amp;lt; Set Name( newname1 ),
			
		// Second col, then every 3rd col thereafter
		i == 2 | Modulo( i - 2, 3 ) == 0, //( i - 2 ) % 3

			// Col name change here
			col_Name2 = column(dt,i) &amp;lt;&amp;lt; Get Name;
			newname2 = second || "_" || col_Name2;
			eval( column(allcols[i] ) ) &amp;lt;&amp;lt; Set Name( newname2 ),
		
		// Third col, then every 3rd col thereafter
		i == 3 | Modulo( i - 3, 3 ) == 0,
			
			// Col name change here
			col_Name3 = column(dt,i) &amp;lt;&amp;lt; Get Name;
			newname3 = third || "_" || col_Name3;
			eval( column(allcols[i] ) ) &amp;lt;&amp;lt; Set Name( newname3 ),
		
	);	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2023 19:52:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Changing-the-name-of-every-third-n-3-column-s-with-specific-name/m-p/613297#M81341</guid>
      <dc:creator>StarfruitBob</dc:creator>
      <dc:date>2023-03-16T19:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the name of every third (n+3) column(s) with specific name; 100+ columns</title>
      <link>https://community.jmp.com/t5/Discussions/Changing-the-name-of-every-third-n-3-column-s-with-specific-name/m-p/613676#M81368</link>
      <description>&lt;P&gt;Hey StarfruitBob,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After fiddling around with it for a while, this worked for me. Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 14:23:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Changing-the-name-of-every-third-n-3-column-s-with-specific-name/m-p/613676#M81368</guid>
      <dc:creator>AlphaLion662</dc:creator>
      <dc:date>2023-03-17T14:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the name of every third (n+3) column(s) with specific name; 100+ columns</title>
      <link>https://community.jmp.com/t5/Discussions/Changing-the-name-of-every-third-n-3-column-s-with-specific-name/m-p/613685#M81371</link>
      <description>&lt;P&gt;In your case you can also increment loop in 3s and set three columns at the same time in single loop&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Probe.jmp");
dt &amp;lt;&amp;lt; Ungroup Columns(); // easier to see what is going on if we remove Responses column group

start_col_idx = 4;
colnames = {"px", "num_after_pipe", "value"};

For(i = start_col_idx, i &amp;lt;= N Cols(dt), i = i + 3, // we can increment in 3s
	Try( // lazy try-catch to exit when we cannot set more column names
		Column(i) &amp;lt;&amp;lt; Set Name(colnames[1]);
		Column(i + 1) &amp;lt;&amp;lt; Set Name(colnames[2]);
		Column(i + 2) &amp;lt;&amp;lt; Set Name(colnames[3]);
	,
		show(exception_msg);
		break();
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1679064993074.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/51214i08D8F91C007519DF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1679064993074.png" alt="jthi_0-1679064993074.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 14:57:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Changing-the-name-of-every-third-n-3-column-s-with-specific-name/m-p/613685#M81371</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-03-17T14:57:01Z</dc:date>
    </item>
  </channel>
</rss>

