recodificación por lotes de muchas columnasHola,
He estado intentando recodificar muchas columnas que contienen una cadena específica en su nombre de columna usando la función recodificar. Creo que estoy bastante cerca, pero el guión se atasca con las evaluaciones de la columna. Entonces me estoy perdiendo algo crucial en alguna parte. Cualquier orientación sería muy apreciada.
Mejor,
Sébastien
Names default to here(1);
Clear log();
New Table( "Subject_Demographics",
Add Rows( 48 ),
New Column( "Unique Subject Identifier",
Character,
"Nominal",
Set Selected,
Set Values(
{"8396882-P0101", "8396882-P0101", "8396882-P0102", "8396882-P0102",
"8396882-P0103", "8396882-P0103", "8396882-P0104", "8396882-P0104",
"8396882-P0201", "8396882-P0201", "8396882-P0202", "8396882-P0202",
"8396882-P0203", "8396882-P0203", "8396882-P0204", "8396882-P0204",
"8396882-P0301", "8396882-P0301", "8396882-P0302", "8396882-P0302",
"8396882-P0303", "8396882-P0303", "8396882-P0304", "8396882-P0304",
"8396882-P0401", "8396882-P0401", "8396882-P0402", "8396882-P0402",
"8396882-P0403", "8396882-P0403", "8396882-P0404", "8396882-P0404",
"8396882-P0501", "8396882-P0501", "8396882-P0502", "8396882-P0502",
"8396882-P0503", "8396882-P0503", "8396882-P0504", "8396882-P0504",
"8396882-P0601", "8396882-P0601", "8396882-P0602", "8396882-P0602",
"8396882-P0603", "8396882-P0603", "8396882-P0604", "8396882-P0604"}
)
),
New Column( "Alertness - Recoded",
Character,
"Nominal",
Set Selected,
Set Values(
{"", "", "", "", "", "", "", "", "", "", "Abnormal Finding",
"Abnormal Finding", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
"Abnormal Finding", "Abnormal Finding", "Abnormal Finding", "", "", "",
"", "Abnormal Finding", "Abnormal Finding", "", "", "", "", "", "", "",
"", "", ""}
)
),
New Column( "Xyx Reflex - Recoded",
Character,
"Nominal",
Set Selected,
Set Values(
{"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
"Abnormal Finding", "Normal", "Normal", "", "", "", "", "Normal",
"Normal", "Normal", "Normal", "Normal", "Normal", "Normal", "Normal",
"Normal", "Normal", "Normal", "Normal", "Normal", "Normal", "Normal",
"Normal", "Abnormal Finding", "Abnormal Finding", "Normal", "Normal",
"Normal", "Normal", "", "", "", "", "Abnormal Finding",
"Abnormal Finding", "Normal", "Normal", "Normal", "Normal", "Normal",
"Normal", "Normal", "Normal", "Normal", "Normal"}
)
),
New Column( "Ataxia - Recoded",
Character,
"Nominal",
Set Selected,
Set Values(
{"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
"Abnormal Finding", "Abnormal Finding", "", "", "Abnormal Finding",
"Abnormal Finding", "", "", "", "", "", "", "", "", "", "", "", "",
"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
"Abnormal Finding", "", "", "Abnormal Finding", "Abnormal Finding", "",
"", "", "", "Abnormal Finding", "Abnormal Finding", "", "", "", "", "",
"", "", "", "Abnormal Finding", "Abnormal Finding"}
)
)
);
subject_incidence = Data Table( "Subject_Demographics" );
a = "Recoded";
col = subject_incidence << get column names( string );
show(col);
nc = N Items( col );
For( i = 1, i <= nc, i++,
If( Contains( col[i], a ),
subject_incidence << Begin Data Update;
subject_incidence << Recode Column(
column(subject_incidence, col[i]),
{Map Value( _rcOrig, {"", "Not Reported"}, Unmatched( _rcNow ) )},
Target Column( column(subject_incidence, col[i] ))
);
subject_incidence << End Data Update
)
);ScriptingRe: recodificación por lotes de muchas columnasDentro de la función de columna de recodificación, JMP ya no conoce la variable col, por lo que debe evaluar esa parte del script antes de la columna de recodificación evalúa.Para hacer eso, puede usar las funciones Eval, Eval Expr y Expr, como esta:
Names default to here(1);
dtSD = New Table( "Subject_Demographics",
Add Rows( 48 ),
New Column( "Unique Subject Identifier",
Character,
"Nominal",
Set Selected,
Set Values(
{"8396882-P0101", "8396882-P0101", "8396882-P0102", "8396882-P0102",
"8396882-P0103", "8396882-P0103", "8396882-P0104", "8396882-P0104",
"8396882-P0201", "8396882-P0201", "8396882-P0202", "8396882-P0202",
"8396882-P0203", "8396882-P0203", "8396882-P0204", "8396882-P0204",
"8396882-P0301", "8396882-P0301", "8396882-P0302", "8396882-P0302",
"8396882-P0303", "8396882-P0303", "8396882-P0304", "8396882-P0304",
"8396882-P0401", "8396882-P0401", "8396882-P0402", "8396882-P0402",
"8396882-P0403", "8396882-P0403", "8396882-P0404", "8396882-P0404",
"8396882-P0501", "8396882-P0501", "8396882-P0502", "8396882-P0502",
"8396882-P0503", "8396882-P0503", "8396882-P0504", "8396882-P0504",
"8396882-P0601", "8396882-P0601", "8396882-P0602", "8396882-P0602",
"8396882-P0603", "8396882-P0603", "8396882-P0604", "8396882-P0604"}
)
),
New Column( "Alertness - Recoded",
Character,
"Nominal",
Set Selected,
Set Values(
{"", "", "", "", "", "", "", "", "", "", "Abnormal Finding",
"Abnormal Finding", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
"Abnormal Finding", "Abnormal Finding", "Abnormal Finding", "", "", "",
"", "Abnormal Finding", "Abnormal Finding", "", "", "", "", "", "", "",
"", "", ""}
)
),
New Column( "Xyx Reflex - Recoded",
Character,
"Nominal",
Set Selected,
Set Values(
{"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
"Abnormal Finding", "Normal", "Normal", "", "", "", "", "Normal",
"Normal", "Normal", "Normal", "Normal", "Normal", "Normal", "Normal",
"Normal", "Normal", "Normal", "Normal", "Normal", "Normal", "Normal",
"Normal", "Abnormal Finding", "Abnormal Finding", "Normal", "Normal",
"Normal", "Normal", "", "", "", "", "Abnormal Finding",
"Abnormal Finding", "Normal", "Normal", "Normal", "Normal", "Normal",
"Normal", "Normal", "Normal", "Normal", "Normal"}
)
),
New Column( "Ataxia - Recoded",
Character,
"Nominal",
Set Selected,
Set Values(
{"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
"Abnormal Finding", "Abnormal Finding", "", "", "Abnormal Finding",
"Abnormal Finding", "", "", "", "", "", "", "", "", "", "", "", "",
"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
"Abnormal Finding", "", "", "Abnormal Finding", "Abnormal Finding", "",
"", "", "", "Abnormal Finding", "Abnormal Finding", "", "", "", "", "",
"", "", "", "Abnormal Finding", "Abnormal Finding"}
)
)
);
a = "Recoded";
col = dtSD << get column names( );
dtSD << Begin Data Update;
For( i = 1, i <= N Items( col ), i++,
If( Contains( col[i], a ),
//Need to evaluate the name of the column before
e = Eval Expr(
Expr( dtSD ) << Recode Column(
As Column( Expr( col[i] ) ),
{Map Value( _rcOrig, {"", "Not Reported"}, Unmatched( _rcNow ) )},
Target Column( As Column( Expr( col[i] ) ) )
);
);
show(e); write("\!n");
eval(e);
)
);
dtSD << End Data Update
Tenga en cuenta que guardé la expresión como e para que pudiera escribirse en el registro antes de ser evaluada.Podría haber puesto Eval (Eval Expr (en la misma línea.
Hay muchas formas de construir este código, aquí hay algunos ejemplos:
Inserte una expresión en otra usando Eval Insert, Eval Expr, Parse y Substitute