cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

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

Try statement with Group Columns

I have a list of columns I want to group but the script fails if any of the columns are absent.  A try statement does not seem to fix the problem.

dt = Current Data Table();

Try( dt <<  Group Columns ("TM", {:Param_1, :Param_2, :Param_3}));

Slán



SpannerHead
2 ACCEPTED SOLUTIONS

Accepted Solutions
mmarchandFSLR
Level VI

Re: Try statement with Group Columns

If you want to group all columns present in that list (even if, say, :Param_2 is missing), you could try something like this.

 

Names Default To Here( 1 );
cols = {:a, :b, :c, :d, :e};
dt << Group Columns( "Some Columns", Filter Each( {v, i}, cols, dt << Has Column( Char( Name Expr( v ) ) ) ) );

View solution in original post

SpannerHead
Level VI

Re: Try statement with Group Columns

Had to tweak this a bit to identify dt.

Names Default To Here( 1 );
dt = Current Data Table();
cols = {:a, :b, :c, :d, :e};
dt << Group Columns( "Some Columns", Filter Each( {v, i}, cols, dt << Has Column( Char( Name Expr( v ) ) ) ) );

Slán



SpannerHead

View solution in original post

3 REPLIES 3
mmarchandFSLR
Level VI

Re: Try statement with Group Columns

If you want to group all columns present in that list (even if, say, :Param_2 is missing), you could try something like this.

 

Names Default To Here( 1 );
cols = {:a, :b, :c, :d, :e};
dt << Group Columns( "Some Columns", Filter Each( {v, i}, cols, dt << Has Column( Char( Name Expr( v ) ) ) ) );
SpannerHead
Level VI

Re: Try statement with Group Columns

Had to tweak this a bit to identify dt.

Names Default To Here( 1 );
dt = Current Data Table();
cols = {:a, :b, :c, :d, :e};
dt << Group Columns( "Some Columns", Filter Each( {v, i}, cols, dt << Has Column( Char( Name Expr( v ) ) ) ) );

Slán



SpannerHead
jthi
Super User

Re: Try statement with Group Columns

My suggestion would be to avoid :col and use strings. With JMP19 you can use Set Intersection

Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");

g = {"age", "sex", "height", "test", "test2"};

mycols = Set Intersection(dt << Get Column Names("String"), g);

dt << Group Columns("MyGroup", mycols);

In earlier versions Associative Arrays (or Filter Each) can replace Set Intersection

-Jarmo

Recommended Articles