ricerca e sostituzione dell'intestazione di colonnaCiao,
Posso sostituire il nome dell'intestazione della colonna con il nome esatto utilizzando :altezza << Imposta Nome( "prova" );
Se ho un elenco di testo che voglio sostituire con "".
Come procedo con quello?
"nome" "ora" "sesso" "altezza abc peso" "peso xyz" "12 altezza test"
KATIE 12 FA 59 95 59
LUISA 12 FA 61 123 61
Risultato finale:
"nome" "ora" "sesso" "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?
)
);
ScriptingRi: cerca e sostituisci intestazione di colonnaCiao Sam,
Sembra che il problema riguardi la ridenominazione diretta della colonna nel secondo ciclo (j) in cui si sta ancora effettuando la sostituzione.
Una possibile soluzione (mostrata di seguito) è modificare l'elenco delle intestazioni (hl) e quindi rinominare la colonna dopo che sono state apportate tutte le modifiche:
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
);
Spero possa essere d'aiuto.
Migliore,
ST
Ri: cerca e sostituisci intestazione di colonnaHo provato a definire l'elenco in anticipo e fare un doppio ciclo nidificato. Si sostituisce solo su stringaReplace[3].
headerList = dt << get column names( string );
stringReplace = List();
stringReplace[1] = "height";
stringReplace[2] = "e";
stringReplace[3] = "a";
For( i = 1, i <= N Items( headerList ), i++,
For( j = 1, j <= N Items( stringReplace ), j++,
Column( dt, i ) << set name( Substitute(headerList[i], stringReplace[j], "" ) )
);
);
Ri: cerca e sostituisci intestazione di colonnaCiao Sam,
Ho riscontrato 2 problemi nel tuo script:
- Hai usato il concatenato "||" codice per rappresentare la tua istruzione "Or" (dovrebbe essere "|")
- JMP non consente di denominare la colonna come " ".
Inoltre, in genere è più rapido e semplice chiamare la colonna in base al numero anziché eseguire l'iterazione nell'elenco dei nomi di colonna
Quindi, ecco cosa mi è venuto in mente:
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 ""?
)
);