@txnelson just used summarize() inside as constant:
https://community.jmp.com/t5/Discussions/Alphabetical-Ranking-of-Nominal-Data/m-p/822725/highlight/t...
As Constant( Summarize( theLevels = by( :age ) ) );
Contains( theLevels, Char( :age ) );
Very interesting approach!
For as constant, the scripting index provides the example
Names Default To Here( 1 );
New Table( "As Constant Demo Table 1",
Add Rows( 10 ),
New Column( "Non-Constant", Formula( Random Uniform() ) ),
New Column( "Constant", Formula( As Constant( Random Uniform() ) ) )
);
this is easy to understand - As Constant( Random Uniform() )
is executed just once and the return value is used for the other rows.
The thing that puzzled me: The return value of Summarize is empty and actually, it's theLevels
which we are interested in.
So, the actual trick is
as constant: "is executed just once"!
very useful!
Could be used for:
as constant("JMP just started to evaluate column xyz");
Let's use this trick for another application: to open an auxiliary data table.
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column( " col",
Formula(
as constant (
dt = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
nr = N Rows( dt );
);
Eval( (EvalExpr(myrows= dtsum << get rows where( :age == Expr(dt:age[row()])))));
Print(:age, myrows);
dtsum[myrows, 2]
)
);
But it's not as easy as I expected ....
Hm, it's quite late - I don't have any idea why: