cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
aumair
Level III

Select specific columns from a table

Hi All

 
I have two tables and I want to subset only specific columns of the Main_Table, which are present as row values in the Cols_Needed table.

 

For example for the tables below, I want to subset column A, I and F of Main_Table, because "A', "I" and "F" are present as row values in the Cols_Needed table. 

 

Thanks!

Ahmad  

 

 

dt = New Table( "Main_Table",
Add Rows( 8 ),
New Column( "A", Numeric, Continuous, Format( "Best", 12 ), Set Values( [1, 2, 3, 1, 1, 1, 1, 1] ) ),
New Column( "B", Numeric, Continuous, Format( "Best", 12 ), Set Values( [4, 5, 6, 1, 1, 1, 1, 1] ) ),
New Column( "C", Numeric, Continuous, Format( "Best", 12 ), Set Values( [7, 8, 9, 1, 1, 1, 1, 1] ) ),
New Column( "D", Numeric, Continuous, Format( "Best", 12 ), Set Values( [10, 11, 12, 1, 1, 1, 1, 1] ) ),
New Column( "E", Numeric, Continuous, Format( "Best", 12 ), Set Values( [13, 14, 15, 1, 1, 1, 1, 1] ) ),
New Column( "F", Numeric, Continuous, Format( "Best", 12 ), Set Values( [5, 2, 3, 1, 1, 1, 1, 1] ) ),
New Column( "G", Numeric, Continuous, Format( "Best", 12 ), Set Values( [99, 8, 9, 1, 1, 1, 1, 1] ) ),
New Column( "I", Numeric, Continuous, Format( "Best", 12 ), Set Values( [15, 14, 15, 1, 1, 1, 1, 1] ) )
);

dt = New Table( "Cols_Needed",
Add Rows( 3 ),
New Column( "Col", Character, Set Values( {"A", "I", "F"}) ),
New Column( "Val", Numeric, Continuous, Format( "Best", 12 ), Set Values( [1,2,3] ) )
);

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Level X

Re: Select specific columns from a table

Names Default To Here( 1 );

dt1 = New Table( "Main_Table",
	Add Rows( 8 ),
	New Column( "A", Numeric, Continuous, Format( "Best", 12 ), Set Values( [1, 2, 3, 1, 1, 1, 1, 1] ) ),
	New Column( "B", Numeric, Continuous, Format( "Best", 12 ), Set Values( [4, 5, 6, 1, 1, 1, 1, 1] ) ),
	New Column( "C", Numeric, Continuous, Format( "Best", 12 ), Set Values( [7, 8, 9, 1, 1, 1, 1, 1] ) ),
	New Column( "D", Numeric, Continuous, Format( "Best", 12 ), Set Values( [10, 11, 12, 1, 1, 1, 1, 1] ) ),
	New Column( "E", Numeric, Continuous, Format( "Best", 12 ), Set Values( [13, 14, 15, 1, 1, 1, 1, 1] ) ),
	New Column( "F", Numeric, Continuous, Format( "Best", 12 ), Set Values( [5, 2, 3, 1, 1, 1, 1, 1] ) ),
	New Column( "G", Numeric, Continuous, Format( "Best", 12 ), Set Values( [99, 8, 9, 1, 1, 1, 1, 1] ) ),
	New Column( "I", Numeric, Continuous, Format( "Best", 12 ), Set Values( [15, 14, 15, 1, 1, 1, 1, 1] ) )
);

dt2 = New Table( "Cols_Needed",
	Add Rows( 3 ),
	New Column( "Col", Character, Set Values( {"A", "I", "F"} ) ),
	New Column( "Val", Numeric, Continuous, Format( "Best", 12 ), Set Values( [1, 2, 3] ) )
);

subsetCols = Column( dt2, "Col" ) << getValues;

dt3 = dt1 << Subset( Columns( subsetCols ) );

View solution in original post

1 REPLY 1
ian_jmp
Level X

Re: Select specific columns from a table

Names Default To Here( 1 );

dt1 = New Table( "Main_Table",
	Add Rows( 8 ),
	New Column( "A", Numeric, Continuous, Format( "Best", 12 ), Set Values( [1, 2, 3, 1, 1, 1, 1, 1] ) ),
	New Column( "B", Numeric, Continuous, Format( "Best", 12 ), Set Values( [4, 5, 6, 1, 1, 1, 1, 1] ) ),
	New Column( "C", Numeric, Continuous, Format( "Best", 12 ), Set Values( [7, 8, 9, 1, 1, 1, 1, 1] ) ),
	New Column( "D", Numeric, Continuous, Format( "Best", 12 ), Set Values( [10, 11, 12, 1, 1, 1, 1, 1] ) ),
	New Column( "E", Numeric, Continuous, Format( "Best", 12 ), Set Values( [13, 14, 15, 1, 1, 1, 1, 1] ) ),
	New Column( "F", Numeric, Continuous, Format( "Best", 12 ), Set Values( [5, 2, 3, 1, 1, 1, 1, 1] ) ),
	New Column( "G", Numeric, Continuous, Format( "Best", 12 ), Set Values( [99, 8, 9, 1, 1, 1, 1, 1] ) ),
	New Column( "I", Numeric, Continuous, Format( "Best", 12 ), Set Values( [15, 14, 15, 1, 1, 1, 1, 1] ) )
);

dt2 = New Table( "Cols_Needed",
	Add Rows( 3 ),
	New Column( "Col", Character, Set Values( {"A", "I", "F"} ) ),
	New Column( "Val", Numeric, Continuous, Format( "Best", 12 ), Set Values( [1, 2, 3] ) )
);

subsetCols = Column( dt2, "Col" ) << getValues;

dt3 = dt1 << Subset( Columns( subsetCols ) );

Recommended Articles