cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Miki
Level II

How do I script a recode into new column function?

Hi, 

I've been searching for an answer for this for a few hours, but oddly can't find one.

 

I have data that represents the serial numbers of the answers a person has given each question. I need to recode the serial number into ranks, but keep the original answers. I need to do that for 90 questions (where each answer has a different serial number). What is the best way to do that? The only way I could think of was writing a script for each question, I just need to know how to write in the script to recode it into a new column. Any suggestions will be most appreciated. 

 

Thanks in advance.

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: How do I script a recode into new column function?

You can easily do what you want, by just building a table where you match up the serial number with it's ranking

40041 4
40042 3
40043 2
40044 1
33151 4
33152 3
33153 2

 

Then, what you do is read in that table.

Next take your questions data table and stack all 90 questions using

     Tables==>Stack

This will create a new table with a column called Label and one called Data.  Label will contain the column name from the original table, and Data will contain the serial number. 

Then what you do, is to use 

     Tables==>Join

to put the stacked question data together with the ranks data.  If you indicate to the Join platform to match the Serial Number column from the ranks data table, with the Data column in the stacked table, JMP will create a new table with the data matched up.

Now all you have to do is to use

     Tables==>Split

to transform the newly joined table back into the original shaped data table.  You will end up with a data table with both the original serial number and the ranks data

Jim

View solution in original post

Re: How do I script a recode into new column function?

A non-scripting option is also available.

 

Under the Columns > Recode you should see a "Done" button up in the right hand corner of the dialog box.  That is essentially a drop down menu that lists 4 choices for saving your recoded data.

In Place, New Column, Formula Column and Script.  Choosing the first option will overwrite your original data, the next two will create a new column and so on.  The Formula Column is a nice option because it creates a formula for what you have recoded.  This gives you a record of what and how you chose to recode your data.

 

HTH

Bill

 

 

View solution in original post

8 REPLIES 8
txnelson
Super User

Re: How do I script a recode into new column function?

Do the "Serial Numbers" for each question equate to the same "rank"?  Is there a table that has the relationship between the "Serial Numbers" and the "ranks"?  Or when you say "ranks", do you want to some how calcualte a statistical ranking?

 

Could you possibly provide a small sample of your initial data table and what you need as your final results?  

 

 

Jim
Miki
Level II

Re: How do I script a recode into new column function?

Thanks for your reply.

Each question has 5 possible answers differing from question to question, and the ranking of the answers is always 1-5. But, like I said, due to the nature of the excell file, each answer only has a serial number and not its rank. What I need to do is to fit a rank for each answer. I have the rankings on the test itself (not on a table).

I really don't see a way to do this other than to script a recode command, and then manually write it in for each question. Am I wrong? 

It is important though, that I don't lose the original data, so I need to recode it into new columns. How do I add that into the script?

 

The data looks something like that:

 

subject numberQuestion 1Question 2
14004233157
24004133154
34004333156
44004233156
54004433155
64004533153

 

txnelson
Super User

Re: How do I script a recode into new column function?

You can easily do what you want, by just building a table where you match up the serial number with it's ranking

40041 4
40042 3
40043 2
40044 1
33151 4
33152 3
33153 2

 

Then, what you do is read in that table.

Next take your questions data table and stack all 90 questions using

     Tables==>Stack

This will create a new table with a column called Label and one called Data.  Label will contain the column name from the original table, and Data will contain the serial number. 

Then what you do, is to use 

     Tables==>Join

to put the stacked question data together with the ranks data.  If you indicate to the Join platform to match the Serial Number column from the ranks data table, with the Data column in the stacked table, JMP will create a new table with the data matched up.

Now all you have to do is to use

     Tables==>Split

to transform the newly joined table back into the original shaped data table.  You will end up with a data table with both the original serial number and the ranks data

Jim
Miki
Level II

Re: How do I script a recode into new column function?

Thank you so much!! That is really helpful. I'll try doing that. 

In any case, do you happen to know how I insert the "new column" to a script of recode? This will be helpful with other data as well.

txnelson
Super User

Re: How do I script a recode into new column function?

There are 2 sources of documentation on JSL provided to you when JMP is installed, the Scripting Guide and the Scripting Index.  If you are going to be using JSL, you need to become familiar with both of these.

If you go into the Scripting Index

     Help==>Scripting Index

And then scroll down to 

     Data Table==>Data Table Cols

You will see both the definition of the New Column() function, and at lease 1 example for the function

newcolumn.PNG

Jim
Miki
Level II

Re: How do I script a recode into new column function?

Thank you again. You have helped me tremendously

Re: How do I script a recode into new column function?

A non-scripting option is also available.

 

Under the Columns > Recode you should see a "Done" button up in the right hand corner of the dialog box.  That is essentially a drop down menu that lists 4 choices for saving your recoded data.

In Place, New Column, Formula Column and Script.  Choosing the first option will overwrite your original data, the next two will create a new column and so on.  The Formula Column is a nice option because it creates a formula for what you have recoded.  This gives you a record of what and how you chose to recode your data.

 

HTH

Bill

 

 

Miki
Level II

Re: How do I script a recode into new column function?

Thank you. I'll look into that option as well. I know all the other three, but didn't know what the formula was for.