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
UserID16644
Level V

How to interchange columns using JSL?

Hi all,

 

I have a CSV file that is being used in JMP. However, I need to interchange columns 1 & 2 with Columns 7 & 8. How to do it using JSL. It looks something like this: 

 

Original File

123456789

 

Interchanged columns

783456129
3 REPLIES 3
jthi
Super User

Re: How to interchange columns using JSL?

Do you wish to reorder your columns or just move the data around inside the columns? This should help you with re-ordering of the columns BUT it won't work the same with all JMP versions due to how <<move selected columns did work in some version(s)

Names Default To Here(1);

dt = New Table("Untitled 2",
	Add Rows(0),
	Compress File When Saved(1),
	New Column("1", Numeric, "Continuous", Format("Best", 12), Set Values([])),
	New Column("2", Numeric, "Continuous", Format("Best", 12), Set Values([])),
	New Column("3", Numeric, "Continuous", Format("Best", 12), Set Values([])),
	New Column("4", Numeric, "Continuous", Format("Best", 12), Set Values([])),
	New Column("5", Numeric, "Continuous", Format("Best", 12), Set Values([])),
	New Column("6", Numeric, "Continuous", Format("Best", 12), Set Values([])),
	New Column("7", Numeric, "Continuous", Format("Best", 12), Set Values([])),
	New Column("8", Numeric, "Continuous", Format("Best", 12), Set Values([])),
	New Column("9", Numeric, "Continuous", Format("Best", 12), Set Values([]))
);


wait(1); // demo purposes

collist = dt << Get Column Names("String");
col_order = {"7", "8", "3", "4", "5", "6", "1", "2", "9"};
dt << Move Selected Columns(col_order);
-Jarmo
UserID16644
Level V

Re: How to interchange columns using JSL?

 This works well. But just one question, is it also possible to move only the data inside the columns and not its headers? How is it done using JSL?

txnelson
Super User

Re: How to interchange columns using JSL?

You can either just change the Header names rather than moving the data, or you can actually move the data.  See example below

names default to here(1);
dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );

// Move header is easier than moving all of the data
:weight << set name("new name");
:height << set name("weight");

// One way to move data
theHeights = :weight << get values;
theWeights = :new name << get values;
:new name << set name("height");

:weight << set values(theWeights);
:height << set values(theHeights);
Jim