/*""" Map two columns together
Author: jthi
Creation Date: 2025-06-05
Creation JMP Version: JMP Pro 18.2.0
"""*/
Names Default To Here(1);
dt1 = New Table("Untitled", New Column("Column 1", Character, "Nominal", Set Values({"A", "B", "C"})));
dt2 = New Table("Untitled", New Column("Column 2", Character, "Nominal", Set Values({"E", "F", "G", "H"})));
nw = New Window("Matcher",
Lineup Box(N Col(3),
V List Box(
Panel Box("From - Table: " || (dt1 << get name || ", Column: " || (Column(dt1, 1) << get name)),
window:lb_from = List Box(Column(dt1, 1) << get values)
),
Panel Box("To - Table: " || (dt2 << get name || ", Column: " || (Column(dt2, 1) << get name)),
window:lb_to = List Box(Column(dt2, 1) << get values)
)
),
Panel Box("Match",
H List Box(align("top"),
Button Box("Match",
<< Set Function(function({this},
from_selections = window:lb_from << get selected;
to_selections = window:lb_to << get selected;
pairs = {};
For Each({{from, to}}, Across(from_selections, to_selections, Count("Shortest")),
Insert Into(pairs, Eval Insert("^from^=^to^"));
);
window:lb_match << Append(pairs);
))),
window:lb_match = List Box({}, << Set N Lines(20))
)
),
Panel Box("Actions",
Lineup Box(N Col(1),
Button Box("OK", << Set Function(function({this},
selections = window:lb_match << get items;
from_values = {};
to_values = {};
For Each({selection}, selections,
{from, to} = Words(selection, "=");
Insert Into(from_values, from);
Insert Into(to_values, to);
);
dt_result = New Table(Eval Insert("^(dt1 << get name)^ mapped to ^(dt2 << get name)^"),
New Column(Column(dt1, 1) << get name, Character, Nominal, Values(from_values)),
New Column(Column(dt2, 1) << get name, Character, Nominal, Values(to_values))
);
If(!(window:cb_keepdialog << get),
this << close window;
);
))),
Button Box("Cancel", << Set Function(function({this}, this << close window))),
Spacer Box(Size(0, 10)),
Button Box("Remove",
window:lb_match << Remove Selected();
),
window:cb_keepdialog = Check Box({"Keep Dialog Open"}, << Set All(1))
)
)
)
);
Write();