cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-765189%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EDeclarar%20una%20variable%20dentro%20de%20una%20f%C3%B3rmula%20de%20columna%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-765189%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHola%2C%3C%2FP%3E%3CP%3E%C2%BFEs%20una%20buena%20pr%C3%A1ctica%20declarar%20una%20variable%20dentro%20de%20una%20f%C3%B3rmula%20de%20columna%3F%20%C2%BFO%20esto%20crea%20riesgo%20de%20errores%3F%20Mi%20f%C3%B3rmula%20funciona%20bien%2C%20pero%20me%20preocupa%20que%20no%20sea%20confiable.%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Erownum%20%3D%20Row()%3B%0AIf(%20%3AMeasurement%20type%20%3D%3D%20%22STUDY_VARIABLE%22%2C%0A%09%3AControl%20means%5BMin(%0A%09%09Current%20Data%20Table()%20%26lt%3B%26lt%3B%20get%20rows%20where(%20%3AMeasurement%20type%20%3D%3D%20%22STUDY_CONTROL%22%20%26amp%3B%20%3AControl%20group%20%3D%3D%20%3AControl%20group%5Brownum%5D%20)%0A%09)%5D%2C%0A%09%3AControl%20means%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3ELa%20configuraci%C3%B3n%20es%20la%20siguiente%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3AEl%20tipo%20de%20medida%20es%20una%20columna%20que%20etiqueta%20cada%20fila%20como%20STUDY_CONTROL%20o%20STUDY_VARIABLE%3C%2FLI%3E%3CLI%3E%3AEl%20grupo%20de%20control%20es%20una%20columna%20que%20utiliza%20una%20etiqueta%20(solo%20una%20letra)%20para%20asociar%20filas%20que%20son%20STUDY_VARIABLES%20con%20la%20media%20apropiada%20(%3AMedias%20de%20control)%20de%20las%20filas%20STUDY_CONTROL%20relevantes.%3C%2FLI%3E%3CLI%3E%3AEl%20grupo%20de%20control%5BRow()%5D%20no%20funcion%C3%B3%2C%20as%C3%AD%20que%20especifiqu%C3%A9%20la%20variable%20rownum%20al%20principio%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%C2%BFEs%20esta%20una%20soluci%C3%B3n%20elegante%20o%20un%20truco%20peligroso%3F%3C%2FP%3E%3CP%3EComo%20segunda%20pregunta%2C%20el%20editor%20me%20advierte%20que%20es%20peligroso%20utilizar%20la%20Tabla%20de%20datos%20actuales()%20en%20una%20f%C3%B3rmula%3A%20%C2%BFexiste%20una%20alternativa%20mejor%3F%3C%2FP%3E%3CP%3EMuchas%20gracias%20por%20cualquier%20ayuda.%20%C2%A1Esta%20es%20mi%20primera%20pregunta!%3C%2FP%3E%3CP%3EDavid%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-802726%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3ERe%3A%20Declarar%20una%20variable%20dentro%20de%20una%20f%C3%B3rmula%20de%20columna%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-802726%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3E%C2%A1Bienvenido%20al%20club!%20%3A)%3C%2Fimg%3E%3A)%3C%2Fimg%3E%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3ECon%20respecto%20a%20su%20pregunta%20sobre%20'Tabla%20de%20datos%20actual()'%2C%20aqu%C3%AD%20hay%20una%20captura%20de%20pantalla%20del%20script%20compartido%20en%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FJMP-Scripters-Club-Discussions%2FScripters-Club-Recording-Building-Robust-and-fail-safe-scripts%2Fm-p%2F788286%23U788286%22%20class%3D%22lia-mention-container-editor-message%20lia-img-icon-forum-thread%20lia-fa-icon%20lia-fa-forum%20lia-fa-thread%20lia-fa%22%20target%3D%22_blank%22%3EScripters%20Club%20Recording%3A%20Building%20Robust%20and%20fail-safe%20scripts%3A%3C%2FA%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ressel_0-1727703983643.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Ressel_0-1727703983643.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Ressel_0-1727703983643.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Ressel_0-1727703983643.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F68723iE83E94E25BD08DCE%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Ressel_0-1727703983643.png%22%20alt%3D%22Ressel_0-1727703983643.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3EAlmacene%20su%20tabla%20en%20una%20variable%20y%20use%20esa%20variable%20en%20su%20secuencia%20de%20comandos.%20En%20el%20ejemplo%20de%20captura%20de%20pantalla%2C%20ser%C3%ADa%20%22dt%22.%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-802740%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3ERe%3A%20Declarar%20una%20variable%20dentro%20de%20una%20f%C3%B3rmula%20de%20columna%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-802740%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3E%C2%A1Realmente%20una%20maravillosa%20conferencia%20sobre%20scripts%20JSL!%3C%2FP%3E%3CP%3EEsta%20hora%20te%20ahorrar%C3%A1%20meses%20de%20dolor%20de%20cabeza%20%3A)%3C%2Fimg%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%20Para%20su%20problema%2C%20por%20favor%20eche%20un%20vistazo%20a%20%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3ECol%20Min%20(...)%3C%2FFONT%3E%20.%3CBR%20%2F%3E%20Har%C3%A1%20todo%20el%20trabajo%20por%20usted%3A%3CBR%20%2F%3E%20No%20es%20necesario%20%3CEM%3Edeclarar%3C%2FEM%3E%20ning%C3%BAn%20rownum%3A%20no%20es%20necesario%20acceder%20a%20la%20%3CSTRONG%3E%3CEM%3Etabla%20de%20datos%20actual%3C%2FEM%3E%3C%2FSTRONG%3E%20ni%20%3CSTRONG%3E%3CEM%3Eobtener%20filas%20where()%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3A%20)%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22hogi_0-1727707451592.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22hogi_0-1727707451592.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F68727i2F216F9A5F2E853B%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22hogi_0-1727707451592.png%22%20alt%3D%22hogi_0-1727707451592.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20to%20Here(1)%3B%0Adt%20%3D%20Open(%20%22%24SAMPLE_DATA%2FBig%20Class.jmp%22%20)%3B%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%20%22Measurement%20type%22%2C%0A%09Character%2C%0A%09Formula(%0A%09%09Map%20Value(%0A%09%09%09%3Asex%2C%0A%09%09%09%7B%22F%22%2C%20%22STUDY_VARIABLE%22%2C%20%22M%22%2C%20%22STUDY_CONTROL%22%7D%0A%09%09)%0A%09)%0A)%3B%0A%3Aweight%20%26lt%3B%26lt%3B%20Set%20Name(%20%22Control%20means%22%20)%3B%0A%3Aage%20%26lt%3B%26lt%3B%20Set%20Name(%20%22Control_Group%22%20)%3B%0A%0A%0A%2F%2F%20%5E%5E%5E%5E%5E%5E%5E%5Eprepare%20table%0A%0A%2F%2F%20vvvvvvvv%20how%20to%20use%20Col%20Min()%0A%0ANew%20Column(%20%22myCol%22%2C%0A%09Formula(%0A%09%09If(%20%3AMeasurement%20type%20%3D%3D%20%22STUDY_VARIABLE%22%2C%0A%09%09%09Col%20Minimum(%0A%09%09%09%09If(%20%3AMeasurement%20type%20%3D%3D%20%22STUDY_CONTROL%22%2C%0A%09%09%09%09%09%3AControl%20means%2C%0A%09%09%09%09%09Empty()%0A%09%09%09%09)%2C%0A%09%09%09%09%3AControl_Group%0A%09%09%09)%2C%0A%09%09%09%3AControl%20means%0A%09%09)%0A%09)%0A)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
Asterix
Level I

Declaring a variable inside a column formula

Hi,

Is it good practice to declare a variable inside a column formula? Or does this create risk of errors? My formula works well, but I'm concerned that it might be unreliable. 

rownum = Row();
If( :Measurement type == "STUDY_VARIABLE",
	:Control means[Min(
		Current Data Table() << get rows where( :Measurement type == "STUDY_CONTROL" & :Control group == :Control group[rownum] )
	)],
	:Control means
);

The setup is as follows:

  • :Measurement type is a column which labels each row as either STUDY_CONTROL or STUDY_VARIABLE
  • :Control group is a column which uses a label (just a letter) to associate rows which are STUDY_VARIABLES with the appropriate mean (:Control means) of the relevant STUDY_CONTROL rows
  • :Control group[Row()] didn't work, so I specified the rownum variable up front

Is this an elegant solution or a dangerous hack?

As a second question, the editor warns me that it's dangerous to use Current Data Table() in a formula - is there a better alternative?

Many thanks for any assistance - this is my first question!

David

2 REPLIES 2
Ressel
Level VII

Re: Declaring a variable inside a column formula

Welcome to the club!:):)

 

Regarding your question on 'Current Data Table()', here a screenshot from the shared script in Scripters Club Recording: Building Robust and fail-safe scripts:

Ressel_0-1727703983643.png

 

Store your table in a variable and use that variable in your script. In the screenshot example, that'd be 'dt'.

 

hogi
Level XIII

Re: Declaring a variable inside a column formula

Indeed a wonderful lecture on JSL scripting!

This 1hr will save you months of headache : )

For you problem, please have a look at Col Min( ...).
It will do all the job for you:
No need to declare any rownum - no need to access the current data table nor to get rows where()

: )

hogi_0-1727707451592.png

 

Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column( "Measurement type",
	Character,
	Formula(
		Map Value(
			:sex,
			{"F", "STUDY_VARIABLE", "M", "STUDY_CONTROL"}
		)
	)
);
:weight << Set Name( "Control means" );
:age << Set Name( "Control_Group" );


// ^^^^^^^^prepare table

// vvvvvvvv how to use Col Min()

New Column( "myCol",
	Formula(
		If( :Measurement type == "STUDY_VARIABLE",
			Col Minimum(
				If( :Measurement type == "STUDY_CONTROL",
					:Control means,
					Empty()
				),
				:Control_Group
			),
			:Control means
		)
	)
)

Recommended Articles