cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
bernie426
Level II

Moving new column

As an example on the Big Class.jmp, I will like to move the created new column after age column.

As the script below, the move selected columns script does not work, the new column still created at the end.

Can anyone help this out? Many Thanks,

Names Default To Here( 1 );

Open( "$SAMPLE_DATA/Big Class.jmp" );

New Column( "example", Numeric, Continuous, Width( 5 ), <<Set Each Value( 100 ) );

<<Move Selected Columns({"example"},After("age"))

2 ACCEPTED SOLUTIONS

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Moving new column

Eval() would not be not needed if assigning a Column() instead of a string to myAfter 

Example:

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
myAfter = Column(dt, "sex");
dt << New Column("example", <<Set Each Value(100), <<Set Selected(1));
dt << Move Selected Columns(After(myAfter));

View solution in original post

Vball247
Level V

Re: Moving new column

Thanks, good to know, this helps because I do pull a list of user selected columns in my script using << Get Selected Columns. Was going off the syntax guide, where it seems that After("name") acts like Column(dt,"name"). I'm still confused by a list of columns vs. a list of column names vs. a list of character strings of the column names and where they can be used to reference a column.

 

You can also move columns without first selecting them in the data table by using the following syntax.

dt << Move Selected Columns( {"name"}, To First );

dt << Move Selected Columns( {"name"}, To Last );

dt << Move Selected Columns( {"name"}, After( "name" ) );

 

View solution in original post

6 REPLIES 6
bernie426
Level II

Re: Moving new column

Sorry, I found that should be

dt=Current Data Table();

dt<<move selected columns({"example"},After("sex"));

syl022
Level I

Re: Moving new column

Hello,

This can be done by a simple procedure. In your data table, go to "Cols" and select "Reorder Columns." Then, you can change the order of the column as you want. Wish it helped.

Vball247
Level V

Re: Moving new column

It appears not to like sending the message to the assumed current data table, your code was not specifying it. It works if you specify the data table as below. I am working on something similar, new column that I want to replace the old column in a large number of columns for the user, so it is in the same location that they are used to seeing it. My text string goes where "example" should go, but now getting the Move Column dialog pop-up. At least I know the "After" should work. Using JMP13.0.

Names Default To Here( 1 );

Open( "$SAMPLE_DATA/Big Class.jmp" ); 

dt = Current Data Table();

New Column( "example", Numeric, Continuous, Width( 5 ), <<Set Each Value( 100 ) );

dt << Move Selected Columns({"example"},After("sex"));

 

Vball247
Level V

Re: Moving new column

Here's my problem. If I use a variable for the After("name") it goes to the dialog:

 

Names Default To Here( 1 ); 

Open( "$SAMPLE_DATA/Big Class.jmp" ); 

dt = Current Data Table();

New Column( "example", Numeric, Continuous, Width( 5 ), <<Set Each Value( 100 ) );

myAfter = "sex";

dt << Move Selected Columns({"example"},After(myAfter));

 

If I evaluate by using After(Eval(myAfter)) it works. If you have a variable in the list, also has to Eval first.

 

Names Default To Here( 1 ); 

Open( "$SAMPLE_DATA/Big Class.jmp" ); 

dt = Current Data Table();

New Column( "example", Numeric, Continuous, Width( 5 ), <<Set Each Value( 100 ) );

myAfter = "sex";

dt << Move Selected Columns({"example"},After(Eval(myAfter))); 

ms
Super User (Alumni) ms
Super User (Alumni)

Re: Moving new column

Eval() would not be not needed if assigning a Column() instead of a string to myAfter 

Example:

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
myAfter = Column(dt, "sex");
dt << New Column("example", <<Set Each Value(100), <<Set Selected(1));
dt << Move Selected Columns(After(myAfter));
Vball247
Level V

Re: Moving new column

Thanks, good to know, this helps because I do pull a list of user selected columns in my script using << Get Selected Columns. Was going off the syntax guide, where it seems that After("name") acts like Column(dt,"name"). I'm still confused by a list of columns vs. a list of column names vs. a list of character strings of the column names and where they can be used to reference a column.

 

You can also move columns without first selecting them in the data table by using the following syntax.

dt << Move Selected Columns( {"name"}, To First );

dt << Move Selected Columns( {"name"}, To Last );

dt << Move Selected Columns( {"name"}, After( "name" ) );