cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
adham_saif
Level I

replacing numbers with strings

hey,

i have a column COL_A, which has 31 rows for wach number between 1 - 31 ( 31 rows of 1, 31 rows of 2 .... etc), and i want to replace those numbers with 31 strings in a specifiec order, for example:

if my string are in this order: horse, cat, dog ....etc, i want to replace the 1's with horse, the 2's with cat, the 3's with dog...., what is the best and fastest way to do it?

3 REPLIES 3
txnelson
Super User

Re: replacing numbers with strings

I believe the fastest way to make this change would be to use "Recode".
Go to the column header for the column you want to change the values for, and right click on the header and select "Recode"
Jim
andersonmj2
Level IV

Re: replacing numbers with strings

I agree with Recode ... but there are other options depending on your usage:

 

1. A script with If-Then-Else statements ... so you would have If C1=="1" Then "Horse" and so on.  Even for 31, that can get cumbersome ... but possible.  I will typically only use this for max of ~6 items.

 

2. LinkID / LinkReference table.  I use this a ton - we run loads of experiments in our development line (I am a happy/busy statistician :) ) with condition keys on the parts we generate done as letters A-Z, and so on.  When setting things up I will always have a core table before randomization with the condition in a column and the conditions in other columns. The COndition is made a LinkID

Since we do many tests, in the results we only use the Condition ID (A-Z) and any specific test information (e.g. where on a part we take the data), and then use LinkReference on the Condition in the results table to go back to the Experimental Conditions table.  Incredibly powerful!

In your case you could simply have a column with 1-31, and a second column with the values Horse, Cat, Dog, etc.  Then use the LinkIDReference feature to get at the values.

Craige_Hales
Super User

Re: replacing numbers with strings

(Also agree with recode.)

A script for this might look something like this

dt = Open( "$sample_data/big class.jmp" );
dt << New Column( "group", character );
label = {"baby", "toddler", "toddler", "pre-k", "k", "1st", "2nd", "3rd", "4th", "5th", "6th", "middle", "middle", "middle", "high", "high", "high"};
For Each Row( group = label[age] );

Grouped agesGrouped ages

The if-then-else approach might be better if your data isn't contiguous, starting at one, or if there are only a few groups.

Craige