cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
New to using JMP? Hit the ground running with the Early User Edition of Discovery Summit. Register now, free of charge.
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
Choose Language Hide Translation Bar
ehchandlerjr
Level V

Use a variable number of columns to join data tables

Hello - I'm trying to do a join as part of a script. However, the "select" and "selectwith" parts are messing me up. I'm dynamically selecting columns of linked data tables earlier in the script, and and passing them as a list to the "select" and "select with" parts. I tried Eval(Eval Expr(Expr())), but that didn't work. I think I'm just misunderstanding the way those two actually take information.

 

Data Table(dt2b) << Join(
    With(Data Table("Experimental Info")),
    Match Flag(1),
    Select(selectedCols1String),
    SelectWith(selectedCols2String),
    By Matching Columns(:ID = :ID),
    Drop multiples(0, 0),
    Include Nonmatches(0, 0),
    Preserve main table order(1)
);

The output for selectedCols1String and selectedCols2String look like this: ":ID, :2Theta, :Data, :Error, :Raw Data, :Raw Error"

 

Thanks!

Edward Hamer Chandler, Jr.
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Use a variable number of columns to join data tables

You shouldn't use a string but rather a list and use Eval with it

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Trial1.jmp");
dt2 = Open("$SAMPLE_DATA/Little.jmp");

select_cols = {"popcorn", "oil amt", "batch", "yield"};
with_cols = {"yield", "batch"};

dt3 = dt << Join(
	With(dt2),
	Select(Eval(select_cols)),
	SelectWith(Eval(with_cols)),
	By Matching Columns(:popcorn = :popcorn, :batch = :batch, :oil amt = :oil)
);

Here I'm using list of strings, but those could be list references also

View more...
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Trial1.jmp");
dt2 = Open("$SAMPLE_DATA/Little.jmp");

select_cols = {:popcorn, :oil amt, :batch, :yield};
with_cols = {:yield, :batch};

dt3 = dt << Join(
	With(dt2),
	Select(Eval(select_cols)),
	SelectWith(Eval(with_cols)),
	By Matching Columns(:popcorn = :popcorn, :batch = :batch, :oil amt = :oil)
);
-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Use a variable number of columns to join data tables

You shouldn't use a string but rather a list and use Eval with it

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Trial1.jmp");
dt2 = Open("$SAMPLE_DATA/Little.jmp");

select_cols = {"popcorn", "oil amt", "batch", "yield"};
with_cols = {"yield", "batch"};

dt3 = dt << Join(
	With(dt2),
	Select(Eval(select_cols)),
	SelectWith(Eval(with_cols)),
	By Matching Columns(:popcorn = :popcorn, :batch = :batch, :oil amt = :oil)
);

Here I'm using list of strings, but those could be list references also

View more...
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Trial1.jmp");
dt2 = Open("$SAMPLE_DATA/Little.jmp");

select_cols = {:popcorn, :oil amt, :batch, :yield};
with_cols = {:yield, :batch};

dt3 = dt << Join(
	With(dt2),
	Select(Eval(select_cols)),
	SelectWith(Eval(with_cols)),
	By Matching Columns(:popcorn = :popcorn, :batch = :batch, :oil amt = :oil)
);
-Jarmo
ehchandlerjr
Level V

Re: Use a variable number of columns to join data tables

Thank you so much! 

Edward Hamer Chandler, Jr.