column header search and replaceHi,
I can replace the column header name with the exact name using :height << Set Name( "test" );
If I have a list of text I want to replace to "".
How do I proceed with that?
"name" "Time" "sex" "height abc weight" "weight xyz" "12 height test"
KATIE 12 F 59 95 59
LOUISE 12 F 61 123 61
Final output:
"name" "Time" "sex" "abc" "xyz" "12 test"
Names Default To Here( 1 );
dt = Open( "C:/JSL/BigClass.jmp" );
headerList = dt << get column names( string );
//:height << Set Name( "test" );
For( i = 1, i <= N Items( headerList ), i++,
If( (headerList[i] == "height" || headerList[i] == "weight"), //trying to find any column header has height or weight and replace with ""
Column( dt, colList[i] ) << set name( " " ) //above are just two examples, maybe put it in list and loop?
)
);
ScriptingRe: column header search and replaceHi Sam,
I found 2 problems in your script:
- You used the concatenate "||" code to represent your "Or" statement (should be "|")
- JMP does not allow for column to be named as " ".
Also, it is usually faster and easier to call the column by number instead of iterating through the Column Name List
So, here is what I came up with:
Names Default To Here( 1 );
dt = Open( "C:\Program Files\SAS\JMP\14\Samples\Data\Big Class.jmp" );
headerList = dt << get column names( string );
For( i = 1, i <= N Items( headerList ), i++,
If( (headerList[i] == "height" | headerList[i] == "weight"), //Fixed the "Or" statement
Column( dt, i ) << set name(substitute (headerList [i], "e", "x")) //Used the substitute function as an example, you can replace any string with ""?
)
);