Choose Language Hide Translation Bar
Highlighted
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
Highlighted
ms
Super User ms
Super User

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

Highlighted
Vball247
Level IV

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
Highlighted
bernie426
Level II

Re: Moving new column

Sorry, I found that should be

dt=Current Data Table();

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

Highlighted
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.

Highlighted
Vball247
Level IV

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 IV

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))); 

Highlighted
ms
Super User ms
Super User

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

Highlighted
Vball247
Level IV

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

Article Labels

    There are no labels assigned to this post.