cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
lisamaley
Level III

Script Run Sequentially

I am trying to create my Save Estimates from my survival platform, then grab the estimates in the newly created table.  The problem is that it will not wait until the Survival table is created before executing the Output expression.  I have tried finish, wait, different orders, etc... and I cannot get this to work, any suggestions?  I have JMP 16.0 with MacBook.

 

Names Default To Here( 0 );

Clear Log();

dt = Current Data Table();

If( Not( Is Scriptable( dt ) ),
	dtsel = Pick File( "Open File", {"JMP|jmp", "All files|*"} );
	If( dtsel == "",
		Stop(),
		Try( dt = Open( dtsel ), Stop() )
	);
);




Sur = Expr(
	Obj = dt << Survival(
		Failure Plot( 1 ),
		Show Points( 1 ),
		Show Shaded Simultaneous CI( 1 ),
		Show Simultaneous CI( 1 ),
		Weibull Fit( 1 )
		//Save Estimates
	);
	dtname = Data Table( dt ) << Get Name;
	Show( dtname );
	
	obj << Save Estimates;
	wait(1);

);

Eval( Survival );

Output = Expr(
	dt2 = Data Table( dtname || " Survival");
	columnnamegroup = Column( dt2, 1 ) << Get Name;
	Groups = Column( dt2, columnnamegroup ) << Get As Matrix;
	Show( Groups );
		
);
Eval(Output);
1 ACCEPTED SOLUTION

Accepted Solutions
ErraticAttack
Level VI

Re: Script Run Sequentially

I think I understand what you're trying to do -- effectively you want the input window for the Survival() platform to be Modal -- you want it to block execution of the script until the window is closed.  You can do that by explicitly defining a window instead of relying on the default behavior.  Here I've created a modal window that contains the input fields, then I grab each input and create the Survival() expression with the correct inputs.

 

Names Default To Here( 1 );
dt = Current Data Table();

If( Not( Is Scriptable( dt ) ),
	dtsel = Pick File( "Open File", {"JMP|jmp", "All files|*"} );
	If( dtsel == "",
		Stop(),
		Try( dt = Open( dtsel ), Stop() )
	);
);

dtname = Data Table( dt ) << Get Name;
validated = 0;

New Window( "Inputs",
	<<Modal
,
	<<On Validate(
		survival = {};
		Insert Into( survival, Substitute( olb[List Box Box( 2 )] << Get Items, {}, Expr( Y() ) ) );
		Insert Into( survival, Substitute( olb[List Box Box( 3 )] << Get Items, {}, Expr( Grouping() ) ) );
		Insert Into( survival, Substitute( olb[List Box Box( 4 )] << Get Items, {}, Expr( Censor() ) ) );
		Insert Into( survival, Substitute( olb[List Box Box( 5 )] << Get Items, {}, Expr( Freq() ) ) );
		Insert Into( survival, Substitute( olb[List Box Box( 6 )] << Get Items, {}, Expr( By() ) ) );
		Insert Into( survival, Insert( Expr( Censor Code() ), olb[Number Edit Box( 1 )] << Get ) );
		Insert Into( survival, Insert( Expr( Plot failure instead of Survival() ), olb[Check Box Box( 1 )] << Get ) );
		survival expr = Expr( Send( dt ) );
		Insert Into( survival expr, Substitute( survival, {}, Expr( Survival() ) ) );
		obj = survival expr;
		obj << Save Estimates;
		validated = 1;
	)
,
	olb = Outline Box( "",
		dt << Survival(
			Failure Plot( 1 ),
			Show Points( 1 ),
			Show Shaded Simultaneous CI( 1 ),
			Show Simultaneous CI( 1 ),
			Weibull Fit( 1 )
			//Save Estimates
		)
	)
);
If( !validated, Stop() );

dt2 = Data Table( dtname || " Survival");
columnnamegroup = Column( dt2, 1 ) << Get Name;
Groups = Column( dt2, columnnamegroup ) << Get As Matrix;
Show( Groups );
Jordan

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Script Run Sequentially

Are you getting any error message in JMP's log? In the example you gave have Sur name for expression and then evaluate Survival, not sure, could that be the issue? It should result in error like: Name Unresolved: Survival in access or evaluation of 'Survival' , Survival/*###*/

 

This seems to work fine after changing then Eval(Survivor) -> Eval(Sur):

Names Default To Here(0);

dt = Open("$SAMPLE_DATA/Rats.jmp");

Sur = Expr(
	obj = dt << Survival(Y(:days), Censor(:Censor), Grouping(:Group));
	dtname = Data Table(dt) << Get Name;
	obj << Save Estimates;
);

Eval(Sur);

Output = Expr(
	dt2 = Data Table(dtname || " Survival");
	columnnamegroup = Column(dt2, 1) << Get Name;
	Groups = Column(dt2, columnnamegroup) << Get As Matrix;
	Show(Groups);
);
Eval(Output);

 

In the fairly rare cases JMP requires adding some delay, wait(0) is usually enough (and if you have lots of formulas  << run formulas might help).

-Jarmo
lisamaley
Level III

Re: Script Run Sequentially

That was a typo on my part, I had it correct before, but it did not work for me even when the two matched.   I tried the wait and it did not work.  I have no formulas, my entire script was copied.

ErraticAttack
Level VI

Re: Script Run Sequentially

I think I understand what you're trying to do -- effectively you want the input window for the Survival() platform to be Modal -- you want it to block execution of the script until the window is closed.  You can do that by explicitly defining a window instead of relying on the default behavior.  Here I've created a modal window that contains the input fields, then I grab each input and create the Survival() expression with the correct inputs.

 

Names Default To Here( 1 );
dt = Current Data Table();

If( Not( Is Scriptable( dt ) ),
	dtsel = Pick File( "Open File", {"JMP|jmp", "All files|*"} );
	If( dtsel == "",
		Stop(),
		Try( dt = Open( dtsel ), Stop() )
	);
);

dtname = Data Table( dt ) << Get Name;
validated = 0;

New Window( "Inputs",
	<<Modal
,
	<<On Validate(
		survival = {};
		Insert Into( survival, Substitute( olb[List Box Box( 2 )] << Get Items, {}, Expr( Y() ) ) );
		Insert Into( survival, Substitute( olb[List Box Box( 3 )] << Get Items, {}, Expr( Grouping() ) ) );
		Insert Into( survival, Substitute( olb[List Box Box( 4 )] << Get Items, {}, Expr( Censor() ) ) );
		Insert Into( survival, Substitute( olb[List Box Box( 5 )] << Get Items, {}, Expr( Freq() ) ) );
		Insert Into( survival, Substitute( olb[List Box Box( 6 )] << Get Items, {}, Expr( By() ) ) );
		Insert Into( survival, Insert( Expr( Censor Code() ), olb[Number Edit Box( 1 )] << Get ) );
		Insert Into( survival, Insert( Expr( Plot failure instead of Survival() ), olb[Check Box Box( 1 )] << Get ) );
		survival expr = Expr( Send( dt ) );
		Insert Into( survival expr, Substitute( survival, {}, Expr( Survival() ) ) );
		obj = survival expr;
		obj << Save Estimates;
		validated = 1;
	)
,
	olb = Outline Box( "",
		dt << Survival(
			Failure Plot( 1 ),
			Show Points( 1 ),
			Show Shaded Simultaneous CI( 1 ),
			Show Simultaneous CI( 1 ),
			Weibull Fit( 1 )
			//Save Estimates
		)
	)
);
If( !validated, Stop() );

dt2 = Data Table( dtname || " Survival");
columnnamegroup = Column( dt2, 1 ) << Get Name;
Groups = Column( dt2, columnnamegroup ) << Get As Matrix;
Show( Groups );
Jordan
lisamaley
Level III

Re: Script Run Sequentially

Yes this works perfectly!  I have done modal windows in the past, but did not know how to do it with the platform.  I tried a few ways and failed.  I guess I did not think about just using a new window.

 

Thank you!

jthi
Super User

Re: Script Run Sequentially

I much prefer @ErraticAttack's solution but now that I understand the question correctly here is another method which might sometimes work. Setting On Close() to the platform window which will then execute whatever you want. This is quite error-prone due to depending on window names, but it could be made bit more robust, by comparing which windows exist before and after execution.

Names Default To Here(0);

dt = Open("$SAMPLE_DATA/Rats.jmp");

Sur = Expr(
	obj = dt << Survival();
	Window("Survival / Reliability") << On Close(Output);
);
Eval(Sur);

Output = Expr(
	dtname = Data Table(dt) << Get Name;
	For Each({window_name}, Get Window List() << Get Window Title,
		If(Contains(window_name, Eval Insert("^dtname^ - Survival of ")),
			cur_w = Window(window_name);
			break();
		);
	);
	obj = cur_w[OutlineBox(1)] << Get Scriptable Object;
	obj << Save Estimates;
	dt2 = Data Table(dtname || " Survival");
	columnnamegroup = Column(dt2, 1) << Get Name;
	Groups = Column(dt2, columnnamegroup) << Get As Matrix;
	Show(Groups);
);
-Jarmo