我有一個包含數百列的資料表。我希望能夠搜尋所有列公式,以查看任何列公式中是否使用了特定列。這可能嗎?
是的......
Names Default To Here( 1 );
dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "/C:/Program Files/JMP/JMPPRO/19/Samples/Data/Big Class.jmp" );
dt << new column("Ratio", formula(:height/:weight));
theFormula = Char(dt:Ratio << get formula);
If( contains(theFormula, "height"), show("found it"));如果您可以存取 JMP Pro,則可以使用 Formula Depot 來完成此操作。

您可以選擇公式列,選擇複製列,開啟新腳本(ctrl + t)並貼上到那裡。然後在腳本編輯器中搜尋。
您也可以嘗試刪除該列,如果正在使用該列,JMP 將顯示類似以下的警告

編輯:
JMP18 中可能還有某種利用列管理器的方法,但我可以找到一種方法。資料字典幾乎可以做到,但它將公式儲存為圖像,因此無法輕鬆搜尋它們

當然還有很多純腳本選項
吉姆,
謝謝你。由於我目前不擅長編寫腳本,您能否向我展示如何讓您的演算法循環遍歷資料表中的所有列並輸出包含目標值的列列表?
雅爾莫,
不幸的是,我沒有 JMP Pro。由於某種原因,當我嘗試刪除列時收到的錯誤訊息未列出包含公式的列。我不知道為什麼。我還認為資料字典可能會有所幫助,但一旦我查看它,我就不知道如何幫助。不過還是謝謝你的幫忙。
我還分享了另一個不依賴 JMP Pro 的選項
您可以選擇公式列,選擇複製列,開啟新腳本(ctrl + t)並貼上到那裡。然後在腳本編輯器中搜尋。


哦哦...那太酷了。我不知道您可以將列貼到腳本編輯器中。
我認為這會起作用。
謝謝!
與@jthi建議複製每列的腳本類似,您可以使用紅色三角形(表左上角)> 複製表腳本(無資料)來複製沒有資料的整個表的腳本。

該腳本將包含用於重新建立表的 jsl,其中將包括所有列公式。將該腳本貼到腳本視窗中,然後從那裡進行搜尋。
我希望這有幫助!
@朱利安
@julian也許這種類型的搜尋可以在某些功能中實現到列管理器?因此,我們也可以搜尋「列屬性」中的值,而不僅僅是過濾到具有特定屬性的值。至少公式、註釋和短/長列名稱是少數列屬性,如果我們可以從中進行搜索,它們可能會受益。
我從@julian的想法開始使用表格腳本並添加了一些函數
- 搜尋公式中的列和
- 顯示搜尋結果:
//Open( "$SAMPLE_DATA/Ship Damage.jmp" );
// get all column formulas via the table script
dt = Current Data Table();
dt << copy table script( "No Data" );
script = Parse( Get Clipboard() );
//convert to List for easier indexing
Substitute Into( script, Expr( New Table() ), Expr( {} ) );
// just keep the columns
allCols = Filter Each( {col}, script, Head( col ) == Expr( New Column() ) );
// convert column info into lists
ColList = Transform Each( {col}, allCols, Substitute( Name Expr( col ), Expr( New Column() ), Expr( {} ) ) );
allColNames = Transform Each( {col}, ColList, tmp = Arg( col, 1 ); If (is string(tmp), tmp, tmp["en"]) );
// keep columns with formulas
ColsWithFormulas = Filter Each( {col}, ColList,Try(col["Formula"]; 1 , 0 ));
ColNames = Transform Each( {col}, ColsWithFormulas, tmp = Arg( col, 1 ); If (is string(tmp), tmp, tmp["en"]) );
ColFormulas = Transform Each( {col}, ColsWithFormulas, col["Formula"] );
// helper function to search for column names in formulas
ContainsExpr = Function( {expression, pattern},
tmp = Substitute( Name Expr( expression ), Name Expr( pattern ), Expr( . ) );
Not( Name Expr( tmp ) == Name Expr( expression ) );
);
summary = New Table("Formuala Overview",
New Column( "column Formula", Character ),
New Column( "used cols", Character ),
);
wait(0);
// fill the summary tale with all combinations of formulas and the used columns
Current Data Table( dt ); // make dt the current data table, otherwise <AS column=""> won't work !
For Each( {myFormula, idx1}, ColFormulas,
For Each( {col}, allColNames,
formulaCol = ColNames[idx1];
dt:formulaCol << Set Header Text Color( "Red" );
If( ContainsExpr( Name Expr( myFormula ), Name Expr( As Column( col ) ) ),
Eval( Eval Expr( summary << add row( {"column Formula"n =Expr(formulaCol ), "used cols"n = Expr( col )} ) ) );
Column(col) << Set Header Background Color( {102, 255, 140} );
)
)
);
// show a tabulate for easy look up
summary << Tabulate(
Show Control Panel( 0 ),
Add Table( Row Table( Grouping Columns( :column Formula, :used cols ) ) ),
Local Data Filter( Mode( Show( 0 ) ), Add Filter( columns( :column Formula, :used cols ) ) )
);</AS>除了透過列背景顏色突出顯示公式中使用的列的方法之外,
人們可能會考慮為公式中使用的列添加指示符號