Hi Sam,
It seems that the issue is with the direct renaming of the column in the second loop (j) where you are still making substitution.
One possible solution (shown below) is to modify the list of headers (hl) and then to rename the column after all changes have been made:
Names Default To Here( 1 );
dt = Open( "C:\Program Files\SAS\JMP\14\Samples\Data\Big Class.jmp" );
hl = dt << get column names( string );
sr = List();
sr[1] = "height"; //
sr[2] = "e"; // Order of replacement strings is critical
sr[3] = "a"; //
For( i = 1, i <= N Items( hl ), i++,
For (j = 1, j <= N Items (sr), j++,
If (contains (hl [i], sr [j]),
txt = substitute (hl [i], sr [j], "x"); // Just for clarity: the expression could be wrapped into the next
Substitute into (hl, hl [i], txt); // Hold all the changes into the hl list
)
);
Column (dt , i ) << set name (hl [i]); // Renames column only after all changes have been made
);
I hope it helps.
Best,
TS
Thierry R. Sornasse