turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- How to know if a table is a linked subset?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 3, 2017 1:56 AM
(1091 views)

Hello everybody,

I would like to determine (using JSL) if the current data table is linked to a main table or not.

I tried "<< Get Table Variable Names" but it didn't work.

Do you have any idea of how we can get this information?

Thanks in advance for your help!

3 ACCEPTED SOLUTIONS

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 3, 2017 5:19 AM
(1819 views)

Solution

you might be able to use the table variable; it will need some testing because I'm not sure if it is always set (update: tried several ways to make a subset and it seems the table variable is always created):

```
dt<<gettablevariable("Linked Subset")
"This subset is linked to Big Class"
// but not linked parent table:
Data Table( "Big Class" )
dt<<gettablevariable("Linked Subset")
""
```

Craige

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 5, 2017 3:12 AM
(1602 views)

Solution

You could test this (along the lines I mentioned earlier):

```
NamesDefaultToHere(1);
// Function to determine if two tables are linked
rLinked = Function({dt1, dt2}, {Default Local},
dt1 << selectAllRows;
if(NRow(dt2 << getSelectedRows) > 0, linked = 1, linked = 0);
dt1 << clearSelect;
dt2 << clearSelect;
linked;
);
// Look at the open tables in the session and see which pairs are linked
linkedTables = Function({}, {Default Local},
nt = NTable();
linkMat = J(nt, nt, .);
tblNames = {};
for(t1=1, t1<=nt, t1++,
InsertInto(tblNames, DataTable(t1) << getName);
for(t2=t1+1, t2<=nt, t2++,
if(rLinked(DataTable(t1), DataTable(t2)), linkMat[t1, t2] = 1, linkMat[t1, t2] = 0);
);
);
EvalList({linkMat, tblNames});
);
// Make some active tables
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Unlinked subset
dt << selectRandomly(0.1);
dt2 = dt << Subset(LinkToOriginalDataTable( 0 ) );
dt2 << setName("Unlinked");
// Linked subset
dt << selectRandomly(0.1);
dt3 = dt << Subset(LinkToOriginalDataTable( 1 ) );
dt3 << setName("Linked");
// Get the 'link matrix'
linkedOrNot = linkedTables();
dt4 = AsTable(linkedOrNot[1], << setName("Linked Tables"), << columnNames(linkedOrNot[2]));
dt4 << NewColumn("Column", Character, Values(linkedOrNot[2]));
dt4 << moveSelectedColumns({"Column"}, ToFirst);
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 6, 2017 6:32 AM
(1564 views)

Solution

Untested (as usual . . . ):

```
NamesDefaultToHere(1);
ClearLog();
// See if a table is a summary of another table
isSummary =
Function({dt}, {Default Local},
ts = dt << Get Table Script Names;
if (Contains(ts, "Source"),
ss = dt << getProperty("Source");
if (Head(Arg(ss, 2)) == Expr(Summary), 1, 0),
0
);
);
// Make a summary table
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt2 = dt1 << Summary(Mean( :height ));
Print(isSummary(dt1));
Print(isSummary(dt2));
```

17 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 3, 2017 2:50 AM
(1087 views)

FWIW, assuming your code makes the tables, you can make linked or unlinked subsets as you require:

```
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Unlinked subset
dt << selectRandomly(0.1);
dt2 = dt << Subset(LinkToOriginalDataTable( 0 ) );
dt2 << setName("Unlinked");
// Linked subset
dt << selectRandomly(0.1);
dt3 = dt << Subset(LinkToOriginalDataTable( 1 ) );
dt3 << setName("Linked");
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 3, 2017 2:55 AM
(1086 views)

Thank you for your answer Ian.

However my objective is not to create a linked subset but to determine if an existing table is linked to another or not.

Sorry if I was not clear enough!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 3, 2017 3:05 AM
(1085 views)

No, I understood, but was implying that you could avoid the 'problem'. But if you want to tell retrospectively, you could do something like:

```
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Unlinked subset
dt << selectRandomly(0.1);
dt2 = dt << Subset(LinkToOriginalDataTable( 0 ) );
dt2 << setName("Unlinked");
// Linked subset
dt << selectRandomly(0.1);
dt3 = dt << Subset(LinkToOriginalDataTable( 1 ) );
dt3 << setName("Linked");
// Function to determine if two tables are linked
rLinked = Function({dt1, dt2}, {Default Local},
dt1 << selectAllRows;
if(NRow(dt2 << getSelectedRows) > 0,
linked = 1,
linked = 0
);
dt1 << clearSelect;
linked;
);
Print(rLinked(dt, dt2), rLinked(dt, dt3));
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 3, 2017 4:50 AM
(1077 views)

Thanks Ian, that is indeed a quite convenient way to solve the problem!

I just need to go one step further. How can we do that if we do not know what is the potential main table (dt in your code)?

Do we have to test all opening tables or is there a faster solution?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 3, 2017 5:19 AM
(1820 views)

you might be able to use the table variable; it will need some testing because I'm not sure if it is always set (update: tried several ways to make a subset and it seems the table variable is always created):

```
dt<<gettablevariable("Linked Subset")
"This subset is linked to Big Class"
// but not linked parent table:
Data Table( "Big Class" )
dt<<gettablevariable("Linked Subset")
""
```

Craige

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 3, 2017 5:45 AM
(1066 views)

Thanks for the suggestion Craige!

I tried "Get Table Variable Names" but not "Get Table Variable"!

I did some tests and it seems to work pretty well!

So far, there is just one particular case where it doesn't work. If I create a summary table linked to the original table, there is no table variable created.

Any idea for this last point?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 3, 2017 6:07 AM
(1063 views)

Yes, the 'summary table' scenario is the one I tried - Hence my replies above. But I'm still left musing over how your JMP session can get into a state where you don't know what's linked to what. But that's OK.

You could easily beuild a 'linking matrix' using 'NTable()' and what I've given above.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 3, 2017 6:22 AM
(1059 views)

I'm going with Ian's answer then.

Why do you need the linked table information? Maybe there is another approach.

Craige

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 3, 2017 6:43 AM
(1053 views)

Actually I am using a script which runs several analyses. In particular, it saves the residuals and other columns from the Fit Model platform, in the current data table. If this table is linked to another one, columns are saved in the original table and not in the current one and it makes fail my script.

So when a user launches the script, I would like to check first if the current table is not linked to another one. And since I am not aware of what the user did before, that is the reason why I am not able to know what could be linked to what.

Let me know if you need more explanations or if something is not clear!

Besides to answer Ian's last post, I see how we could build this linking matrix but if we have a summary table, I am not sure that the previous script will work. If I am not wrong when you select rows in the original table, nothing is selected in the summary table.

So unfortunately this case is still problematic.