RE: Adding Column From Data Table to Another Data TableHi,
I wanted to add a column from my dt data table to my dc data table.
// Opens the Process Template file and sets dc as the reference to it.
dc = Open("Process Template.jmp");
// Sets the Process Template file as the current data table.
dc = Current Data Table();
// References to a column called Time.
Column("Time");
// Creates a column called colTime and sets it to the twelfth column in the current data table.
colTime = Column(12);
// Moves the newInstructionsColumn before the colTime column in the Process Template file.
dc << MoveSelectedColumns({dt:newInstructionsColumn}, Before(colTime));Above is the code I used to do this. There is already column before the colTime column so maybe that's why its not functioning correctly.
Any help would be appreciated.
RE: Adding Column From Data Table to Another Data Table...
RE: Adding Column From Data Table to Another Data TableHi,
Thanks for the reply. The code you provided works in the sense that it adds a new column but the set values part doesn't work as the values are all missing in the new column.
Any ideas why?
RE: Adding Column From Data Table to Another Data TableHi,
Thanks for your reply. I was looking to add an already existing column from my dt table so that it appears before the column colTime in my dc data table. However, there is already a column before colTime in my dc data table.
RE: Adding Column From Data Table to Another Data TableThis might be what you are looking for
Names Default To Here( 1 );
Clear Log();
Clear Globals();
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt1 = Open( "$SAMPLE_DATA/Big Class Families.jmp" );
dt << New Column( "sibling ages", Multiple Response, set values( dt1:sibling ages << get values ) )
RE: Adding Column From Data Table to Another Data Table@Jaz,
When you say add a new column -
1. Are you defining a new column that does not exist in either data table ? Or
2. Are you adding column from one data table to another data table ?
If you want to achieve (1), then you can use the New Column().
If you want to achieve (2), then you can use the Join
RE: Adding Column From Data Table to Another Data TableHi,
They do have a common column but I want to add a new column, not join the two tables. Is there a way to do that?
Thanks.
RE: Adding Column From Data Table to Another Data Table@Jaz,
Do these data tables have common columns ? I would advice using the "Join" function to add columns from data table "dt" to "dc" .
Here is an example
Clear Log(); Clear Globals();
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt1 = Open( "$SAMPLE_DATA/Big Class Families.jmp" );
dt2 = dt << Join(With( dt1 ),
Select( :name, :age, :sex, :height, :weight ),
SelectWith( :sibling ages, :sports ),
By Matching Columns( :name = :name ),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 )
);