recode multiple columns name with regex
Hi all!
I am trying to apply a regex replacement to a Recode Column function in JSL so that the script will go over all columns and apply the regex to all of them, if applicable.
This is the code I've been testing:
Names Default To Here(1);
dt = Current Data Table();
//Create list of columns to be recoded
ColN = dt << Get Column Names();
// Iterate over the list of columns and recode each one
For Each({listitem}, ColN,
dt << Recode Column(
As Column(listitem),
{Regex(_rcNow, "erm", "testtest", GLOBALREPLACE)},
Target Column(Column(listitem))
);
);I am getting this error:
Name Unresolved: LocalTime in access or evaluation of 'LocalTime' , LocalTime/*###*/
LocalTime is the first column out of 13 columns in my dataset.
I would appreciate any help!
ScriptingRe: recode multiple columns name with regexI just realized that I used Recode Column and not a function that will rename the column name...
Is there a dedicated function to recoding a column name? is there another way to accomplish it?
Re: recode multiple columns name with regexA list when specified will not execute any elements within the list. Therefore, the coder needs to force the list to be fully expanded before it is passed to JMP. Below is one way of handling the issue
Names Default To Here( 1 );
dt = Current Data Table();
//Create list of columns to be recoded
ColN = dt << Get Column Names(string);
// Iterate over the list of columns and recode each one
For Each( {listitem}, ColN,show(listitem);
Eval(
Substitute(
Expr(
dt << Recode Column(
As Column( listitem ),
{Regex( __rcNow__, "erm", "testtest", GLOBALREPLACE )},
Target Column( Column( listitem ) )
)
),
Expr( __rcNow__ ), listitem
)
)
);