How to add a prefix to columns indicating their position in table (JSL, scripting)Hi
I would like to add a prefix to column names that indicate their positions in the data table.
For example, the columns of "BIG CLASS .jmp" are renamed from
NAME AGE SEX HEIGHT WEIGHT t o 001_NAME 002_AGE 003_SEX 004_HEIGHT 005_WEIGHT.
The prefix indicates the positon of the column in the table, and it should have a standard length of 3, if necessary padded with leading 0s. Like in the BIG CLASS example.
The challenge is that my JMP tables have 100s of columns and individual adjusting is out of the question.
Thanks a lot in advance
Newbie
Re: How to add a prefix to columns indicating their position in table (JSL, scripting)Names Default to Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
n = N Col( dt );
For( c = 1, c <= n, c++,
name = Column( dt, c ) << Get Name;
prefix = If(
c < 10, "00",
c < 100, "0",
""
) || Char( c ) || "_";
name = prefix || name;
Column( dt, c ) << Set Name( name );
);
Re: How to add a prefix to columns indicating their position in table (JSL, scripting)That's very elegant. Thank you so much! You saved my day!
Re: How to add a prefix to columns indicating their position in table (JSL, scripting)I use a different conversion method, that does not require If() statements:
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
For( c = 1, c <= N Cols( dt ), c++,
Column( dt, c ) << Set Name(
Substr( "00", Length( Char( c ) ) ) || Char( c ) || "_"
|| Char( Column( dt, c ) << Get Name )
)
);