cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Ressel
Level VI

Recoding multiple variables in one column and remembering it as a script

OK, so I have begun familiarizing with JMP and worked successfully on my first script to extract, rearrange and format a data table from a database. Works fine and saves time. As I have developed this script with a copy of Jump into JMP Scripting on my lap, I was naturally interested in understanding the script. So here comes the issue.

 

Think of a manufacturing process requiring lots of different measurements. The database has all test methods in one column and all test results in another column. To get what I want I need to split this table. However, since a lot of what we have in the database is from legacy Excel files, some recoding of the column holding the test names is required due to earlier, erroneous entries. To get to that piece of (re)code I went via Recode... in the Columns menu, and it is the only piece in the script I cannot understand. (It's generally a very basic script.)

In the example posted below, the capital letters and numbers reflect variations of the name of the actual test method used. For example, A is one test (say pH testing), B is another test (e.g. viscosity). A(1), A(2), ... A(n) would all be recoded to A, then B(1), ... B(n) to B, and so on. Now how does the software now from exactly this piece of code which variables belong together? I checked the scripting guide and the scripting index but still don't understand. _rcOrig and _rcNow, what do they mean? The script, i.e. the variables in their respective rows are arranged exactly as they are in my copy of the complete script.

 

Thanks for an answer.

 

dt << Recode Column(
	dt:TestName,
	{Map Value(
		_rcOrig,
		{"A(1)", "A(2)",
		"A(3)", "A(4)",
		"A(5)", "A(6)", "B(1)",
		"B(2)", "C(1)", "C(2)",
		"C(3)", "C(4)", "D(1)", "D(2)", "E(1)",
		"E(2)", "F(1)", "F(2)", "G(1)", "G(2)",
		"H(1)", "H(2)", "I(1)", "I(2)",
		"I(3)", "I(4)", "J(1)", "J(2)", "K(1)",
		"K(2)", "L(1)", "L(2)",
		"M(1)", "M(2)", "M(3)",
		"M(4)"},
		Unmatched( _rcNow )
	)},
	Target Column( col1 )
);
dt << End Data Update;

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Recoding multiple variables in one column and remembering it as a script

I created a new column in a data table with the test values you had in the JSL you provided.

 recode.PNG

I then opened the Recode dialog and made the recode changes.

recode2.PNG

I then went to the red triangle and selected

     Script=>Save to Script Window

and below is what it gave me.

Names Default To Here( 1 );
dt = Data Table( "Big Class" );
dt << Begin Data Update;
col1 = dt << New Column( dt:test );
col1 << Set Name( "test 2" );
dt << Move Selected Columns( {col1}, after( dt:test ) );
dt << Recode Column(
	dt:test,
	{Map Value(
		_rcOrig,
		{"A(1)", "A", "A(2)", "A", "A(3)", "A", "A(4)", "A", "A(5)", "A", "A(6)",
		"A", "B(1)", "B", "B(2)", "B", "C(1)", "C", "C(2)", "C", "C(3)", "C", "C(4)",
		"C", "D(1)", "D", "D(2)", "D", "E(1)", "E", "E(2)", "E", "F(1)", "F", "F(2)",
		"F", "G(1)", "G", "G(2)", "G", "H(1)", "H", "H(2)", "H", "I(1)", "I", "I(2)",
		"I", "I(3)", "I", "I(4)", "I", "J(1)", "J", "J(2)", "J", "K(1)", "K", "K(2)",
		"K", "L(1)", "L", "L(2)", "L", "M(1)", "M", "M(2)", "M", "M(3)", "M", "M(4)",
		"M"},
		Unmatched( _rcNow )
	)},
	Target Column( col1 )
);
dt << End Data Update;

In the example, you can see how the values are set for each of the value/result pairs

Jim

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: Recoding multiple variables in one column and remembering it as a script

I created a new column in a data table with the test values you had in the JSL you provided.

 recode.PNG

I then opened the Recode dialog and made the recode changes.

recode2.PNG

I then went to the red triangle and selected

     Script=>Save to Script Window

and below is what it gave me.

Names Default To Here( 1 );
dt = Data Table( "Big Class" );
dt << Begin Data Update;
col1 = dt << New Column( dt:test );
col1 << Set Name( "test 2" );
dt << Move Selected Columns( {col1}, after( dt:test ) );
dt << Recode Column(
	dt:test,
	{Map Value(
		_rcOrig,
		{"A(1)", "A", "A(2)", "A", "A(3)", "A", "A(4)", "A", "A(5)", "A", "A(6)",
		"A", "B(1)", "B", "B(2)", "B", "C(1)", "C", "C(2)", "C", "C(3)", "C", "C(4)",
		"C", "D(1)", "D", "D(2)", "D", "E(1)", "E", "E(2)", "E", "F(1)", "F", "F(2)",
		"F", "G(1)", "G", "G(2)", "G", "H(1)", "H", "H(2)", "H", "I(1)", "I", "I(2)",
		"I", "I(3)", "I", "I(4)", "I", "J(1)", "J", "J(2)", "J", "K(1)", "K", "K(2)",
		"K", "L(1)", "L", "L(2)", "L", "M(1)", "M", "M(2)", "M", "M(3)", "M", "M(4)",
		"M"},
		Unmatched( _rcNow )
	)},
	Target Column( col1 )
);
dt << End Data Update;

In the example, you can see how the values are set for each of the value/result pairs

Jim
Mauro_Gerber
Level IV

Re: Recoding multiple variables in one column and remembering it as a script

Hi,

 

If its always one Letter, you may want to make a simple formula like this:

 

dt << New Column( "Test_Name", formula( Left(:TestName, 1)));

 

"I thought about our dilemma, and I came up with a solution that I honestly think works out best for one of both of us"
- GLaDOS
Ressel
Level VI

Re: Recoding multiple variables in one column and remembering it as a script

It's not always one letter. The letters are just placeholders for "any test name". I know how the tests belong together, JMP does not unless I tell it. I was wondering how JMP knew. Now I do. I think I'm blind.
Ressel
Level VI

Re: Recoding multiple variables in one column and remembering it as a script

We are blessed to have you in this community. Thank you. Just looking over the original script and pondering when to have the next appointment with my optician.