¿Cómo evalúa JMP una fórmula de columna?@txnelson acaba de usar summary() dentro como constante:
https://community.jmp.com/t5/Discussions/Alphabetical-Ranking-of-Nominal-Data/mp/822725/highlight/true#M100245
As Constant( Summarize( theLevels = by( :age ) ) );
Contains( theLevels, Char( :age ) );
¡Un enfoque muy interesante!
Para una constante , el índice de secuencias de comandos proporciona el ejemplo
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 Resumir is empty and actually, it's theLevels which we are interested in.
Entonces, el truco real es
como constante : "se ejecuta solo una vez" !
¡Muy útil!
Podría usarse para:
as constant("JMP just started to evaluate column xyz");
Utilicemos este truco para otra aplicación: para abrir una tabla de datos auxiliares.
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]
)
);
Pero no es tan fácil como esperaba....
Hm, es bastante tarde, no tengo idea de por qué:

Automatización y scriptingRe: ¿Cómo evalúa JMP una fórmula de columna?La siguiente pregunta -y por tanto el título del post-:
¿Por qué JMP elimina las entradas cuando cierro dtsum ?
Try(close(dt, nosave));
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Data Table( "Big Class" ) << Sort(
By( :age, :height ),
Replace Table
);
dt << New Column( " col",
Formula(
local({tmp,myAge},
as constant (
dt0 = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
//dtsum:age << set name(age2);
nr = N Rows( dt0 );
);
myage = dt:age[row()];
Eval (Eval Expr(myrows = dtsum << get rows where( :age == Expr(myAge))));
Print(myRows);
tmp = contains(dtsum[myrows,2], :height);
if(row()==nr, dt<< runformulas();wait(1);close(dtsum, noSave);Caption("done"));
tmp
)));Re: ¿Cómo evalúa JMP una fórmula de columna?El problema 1 se puede solucionar mediante:
dt << New Column( " col",
Expression,
set each value (
local({tmp,myAge},
as constant (
dt0 = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
//dtsum:age << set name(age2);
nr = N Rows( dt0 );
);
myage = dt:age[row()]; // save as variable and use later here ↘:backhand_index_pointing_down:</img>
Eval (Eval Expr(myrows = dtsum << get rows where( :age == Expr(myAge))));
dtsum[myrows,2]
)));Re: ¿Cómo evalúa JMP una fórmula de columna?Vaya, y el segundo es muy sorprendente, se puede arreglar a través de
//dense rank - with groupby
dt << New Column( " col",
set each value( // <- the first change is here
local({tmp,myAge},
as constant (
dt = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
//dtsum:age << set name(age2);
nr = N Rows( dt );
);
myage = dt:age[row()];
Eval (Eval Expr(myrows = dtsum << get rows where( :age == Expr(myAge))));
tmp = contains(dtsum[myrows,2],dt:height); // <- the second change is here : use dt:height instead of :height to force JMP to use the right table!
if(row()==nr, close(dtsum, noSave));
tmp
)));Esto también soluciona el problema con varias entradas "0" en el enfoque anterior.
Entonces, debajo de la línea, las preguntas no eran:
¿Por qué JMP elimina los valores en dt si la tabla dtsum está cerrada?
La pregunta real era:
¿Por qué JMP utiliza dtsum:height en lugar de dt:height al calcular entradas para la tabla de datos dt ?
Pregunta abierta: ¿por qué dt:height solo soluciona el problema para establecer cada valor() y no para la fórmula()?
Re: ¿Cómo evalúa JMP una fórmula de columna?Ah,
dt << New Column( "dense rank_ grouped by",
Character,
formula (
local({tmp,myAge},
as constant (
dt = Current Data Table();
dtsum = dt << summary( Group( :age, :height ) );
//dtsum:age << set name(age2);
nr = N Rows( dt );
);
rw = row();
myage = dt:age[row()];
Eval (Eval Expr(myrows = dtsum << get rows where( dtsum:age == Expr(myAge)))); // <- use dtsum:age !!!
tmp = contains(dtsum[myrows,2], dt:height[rw]); // <- use dt:height !!!!
if(row()==nr, close(dtsum, noSave));
tmp
)));
@jthi , recuerdo que tuviste un problema similar hace un tiempo: un conflicto si dos tablas tienen nombres de columnas superpuestos.
Agregaré un enlace cuando lo encuentre...
Re: ¿Cómo evalúa JMP una fórmula de columna?¿Te refieres al problema que menciono aquí Error al usar la combinación de establecer cada valor, tablas con el mismo nombre de columna y funciones estadísticas col dentro de un bucle ?
Re: ¿Cómo evalúa JMP una fórmula de columna?Ah, cierto, éste.
Por lo tanto, no es solo << set each value() el que se ve afectado: formula() también puede verse afectado.
Qué suerte que no pude encontrar tu publicación ayer.
No me hubiera atrevido a << establecer cada valor() después de leerlo...
Tal vez: no como solución alternativa, sino como verificación.
Interesante: en mi caso, no hay ninguna estadística col involucrada (como col rank() ).
Tal vez JMP sabe que el código fue creado para crear uno ; )