Arbitrary Recode ScriptI have a character variable with an unknown number of levels. The levels have long text names and I'd like to recode them into something shorter, such as just 1, 2, 3, etc...
I understand how to use Match to recode a given set of levels to other specific values, but would like to ask how to do this if the initial set is unknown. That is, for each new data file the variable to recoded may have a different number of different entries.
Thanks!
Re: Arbitrary Recode ScriptA-ha! I thought that "dt =" was unusual. Turned out I got around it by writing "dt2 = ". Likely a bit inefficient but it worked. I've since changed it to "dt <<" and it works great as well.
Thanks Again!
Re: Arbitrary Recode Scriptoops,
the New Column statement should be
dt << New Column(.................
Re: Arbitrary Recode ScriptPS., Seems somehow dt is being assigned that new column. The original data table is no longer referenced by dt. Is that right?
Re: Arbitrary Recode ScriptSeems I spoke to soon ... that code is creating the desired new variable, but now all my code after that does not work. In particular I tried to move the new variable, then exclude some rows. My move and exclude worked fine before, but now the new variable becomes excluded and hidden?
Is there something that needs to be re-set or turned off? (By the way, I'm using Version 12)
Thanks!
Re: Arbitrary Recode ScriptThat worked great! Thanks very much!
Re: Arbitrary Recode ScriptHere is a small piece of JSL that gives an example of creating a numerical value from the character values found in a column
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Animals.jmp" );
dt = New Column( "Animal Category",
formula(
If( Row() == 1,
Summarize( bygroup = by( :species ) )
);
Loc( bygroup, :species )[1];
)
);