<?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: JMP 18: Select All Columns to the Right of a Specified Column in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863788#M102769</link>
    <description>&lt;P&gt;Contains + indexing using that should make this fairly simple&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 = Data Table("Test Table");

collist = dt &amp;lt;&amp;lt; Get Column Names("String");

adders_idx = Contains(collist, "Adders");
If(adders_idx == 0,
	Throw("No Adders column found");
);

dt &amp;lt;&amp;lt; Select columns(collist[adders_idx + 1::N Items(collist)]);

Show(dt &amp;lt;&amp;lt; Get Selected Columns);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 01 Apr 2025 04:49:50 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2025-04-01T04:49:50Z</dc:date>
    <item>
      <title>JMP 18: Select All Columns to the Right of a Specified Column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863641#M102756</link>
      <description>&lt;P&gt;Looking to select all columns to the right of the column named , Adders. The code below runs but does not visibly select the columns to the right of Adders. The number of columns to the left and right of Adders may vary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;&amp;lt;JSL&amp;gt; Names Default To Here(1);

dt = Data Table("Test Table");
dt &amp;lt;&amp;lt; Bring Window To Front;

Show(dt &amp;lt;&amp;lt; Get Name);

// Step 1: Get all column names and show them
colNames = dt &amp;lt;&amp;lt; Get Column Names();
Show(colNames);

// Step 2: Find the index of the "Adders" column
targetColName = "Adders";
colIndex = Loc(colNames, targetColName);
Show(colIndex); // Should be &amp;gt; 0 if found

// Step 3: Try to visually select all columns to the right
If(colIndex &amp;gt; 0 &amp;amp; colIndex &amp;lt; N Cols(dt),

dt &amp;lt;&amp;lt; Clear Column Selection;

For(i = colIndex + 1, i &amp;lt;= N Cols(dt), i++,
Column(dt, i) &amp;lt;&amp;lt; Set Selected(1);
);

// Step 4: Show what JMP thinks is selected
selected = dt &amp;lt;&amp;lt; Get Selected Columns;
Show(selected);

,
New Window("Error", Text Box("Column 'Adders' not found, or it's the last column."));
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;PRE&gt;dt &amp;lt;&amp;lt; Get Name = "Test Table";
colNames = {A, B, Adders, X, Y};
colIndex = [];&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Mar 2025 20:54:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863641#M102756</guid>
      <dc:creator>WoHNY</dc:creator>
      <dc:date>2025-03-31T20:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: JMP 18: Select All Columns to the Right of a Specified Column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863669#M102757</link>
      <description>&lt;P&gt;I'd make two changes here.&amp;nbsp; You need to specify "string" in your Get Column Names message.&amp;nbsp; You should then change the Loc() function to Contains().&amp;nbsp; Loc() returns a matrix, sometimes empty.&amp;nbsp; Contains() returns an integer (0 when not found).&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 = Data Table("Test Table");
dt &amp;lt;&amp;lt; Bring Window To Front;

Show(dt &amp;lt;&amp;lt; Get Name);

// Step 1: Get all column names and show them
colNames = dt &amp;lt;&amp;lt; Get Column Names( "string" );
Show(colNames);

// Step 2: Find the index of the "Adders" column
targetColName = "Adders";
colIndex = Contains(colNames, targetColName);
Show(colIndex); // Should be &amp;gt; 0 if found

// Step 3: Try to visually select all columns to the right
If(colIndex &amp;gt; 0 &amp;amp; colIndex &amp;lt; N Cols(dt),

dt &amp;lt;&amp;lt; Clear Column Selection;

For(i = colIndex + 1, i &amp;lt;= N Cols(dt), i++,
Column(dt, i) &amp;lt;&amp;lt; Set Selected(1);
);

// Step 4: Show what JMP thinks is selected
selected = dt &amp;lt;&amp;lt; Get Selected Columns;
Show(selected);

,
New Window("Error", Text Box("Column 'Adders' not found, or it's the last column."));
);

 

//Output:

//dt &amp;lt;&amp;lt; Get Name = "Test Table";
//colNames = {"A", "B", "Adders", "X", "Y"};
//colIndex = 3;&lt;BR /&gt;//selected = {:X, :Y};&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Mar 2025 20:47:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863669#M102757</guid>
      <dc:creator>mmarchandFSLR</dc:creator>
      <dc:date>2025-03-31T20:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: JMP 18: Select All Columns to the Right of a Specified Column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863671#M102759</link>
      <description>&lt;P&gt;I'm sure there are other ways to do this, but the following script will find the "Adders" column, then select it and all the columns to the right:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
dt = current data table();

targetCol = "Adders";
targetColNum = 0;

for( i = 1, i &amp;lt;= n cols( dt ), i++, 
	if( column( dt,i ) &amp;lt;&amp;lt; get name == targetCol, targetColNum = i )
);
dt &amp;lt;&amp;lt; select columns( targetColNum::n cols(dt) )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 20:51:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863671#M102759</guid>
      <dc:creator>scott_allen</dc:creator>
      <dc:date>2025-03-31T20:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: JMP 18: Select All Columns to the Right of a Specified Column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863673#M102761</link>
      <description>&lt;P&gt;I edited your initial post and moved the JSL and its output into a JSL window and a Code window respectively, by using the input icons at the top of the edit input window.&lt;/P&gt;
&lt;P&gt;I have also modified your code to have the &amp;lt;&amp;lt; get column names, return strings, and instead of using Loc(), using Contains() to return a single value rather than a matrix value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Data Table("Test Table");
dt &amp;lt;&amp;lt; Bring Window To Front;

Show(dt &amp;lt;&amp;lt; Get Name);

// Step 1: Get all column names and show them
colNames = dt &amp;lt;&amp;lt; Get Column Names(string);
Show(colNames);

// Step 2: Find the index of the "Adders" column
targetColName = "Adders";
// Loc() returns a matrix, contains returns a scaler value
colIndex = contains(colNames, targetColName );
Show( colIndex ); // Should be &amp;gt; 0 if found

// Step 3: Try to visually select all columns to the right
If( colIndex &amp;gt; 0 &amp;amp; colIndex &amp;lt; N Cols( dt ), 

	dt &amp;lt;&amp;lt; Clear Column Selection;

	For( i = colIndex + 1, i &amp;lt;= N Cols( dt ), i++,
		Column( dt, i ) &amp;lt;&amp;lt; Set Selected( 1 )
	);

// Step 4: Show what JMP thinks is selected
	selected = dt &amp;lt;&amp;lt; Get Selected Columns;
	Show( selected );

,
	New Window( "Error", Text Box( "Column 'Adders' not found, or it's the last column." ) )
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Mar 2025 21:08:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863673#M102761</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2025-03-31T21:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: JMP 18: Select All Columns to the Right of a Specified Column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863674#M102762</link>
      <description>&lt;P&gt;Thank you for the corrections.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 21:15:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863674#M102762</guid>
      <dc:creator>WoHNY</dc:creator>
      <dc:date>2025-03-31T21:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: JMP 18: Select All Columns to the Right of a Specified Column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863675#M102763</link>
      <description>&lt;P&gt;Jim: Thank you for the corrections.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 21:15:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863675#M102763</guid>
      <dc:creator>WoHNY</dc:creator>
      <dc:date>2025-03-31T21:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: JMP 18: Select All Columns to the Right of a Specified Column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863676#M102764</link>
      <description>&lt;P&gt;Scott: Thank you for the code which works.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 21:17:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863676#M102764</guid>
      <dc:creator>WoHNY</dc:creator>
      <dc:date>2025-03-31T21:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: JMP 18: Select All Columns to the Right of a Specified Column</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863788#M102769</link>
      <description>&lt;P&gt;Contains + indexing using that should make this fairly simple&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 = Data Table("Test Table");

collist = dt &amp;lt;&amp;lt; Get Column Names("String");

adders_idx = Contains(collist, "Adders");
If(adders_idx == 0,
	Throw("No Adders column found");
);

dt &amp;lt;&amp;lt; Select columns(collist[adders_idx + 1::N Items(collist)]);

Show(dt &amp;lt;&amp;lt; Get Selected Columns);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Apr 2025 04:49:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-18-Select-All-Columns-to-the-Right-of-a-Specified-Column/m-p/863788#M102769</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-04-01T04:49:50Z</dc:date>
    </item>
  </channel>
</rss>

