Subscribe Bookmark RSS Feed

Moving new column

bernie426

Community Trekker

Joined:

Feb 9, 2015

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

6 REPLIES
bernie426

Community Trekker

Joined:

Feb 9, 2015

Sorry, I found that should be

dt=Current Data Table();

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

syl022

Community Trekker

Joined:

Jan 6, 2015

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

Occasional Contributor

Joined:

Nov 1, 2016

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

Occasional Contributor

Joined:

Nov 1, 2016

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

Joined:

Jun 23, 2011

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

Occasional Contributor

Joined:

Nov 1, 2016

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