你好,
我一直在嘗試使用recode函數對許多在其列名中包含特定字符串的列進行重新編碼。 我認為我已經很接近了,但是腳本陷入了列評估的困境。 所以我在某個地方缺少重要的東西。 任何指導將不勝感激。
最好,
塞巴斯蒂安
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
)
);我相信程式碼可以比@ih簡單一點
您的程式碼只需更改為使用 As Column() 函數而不僅僅是 Column() 函數即可使程式碼正確運行
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(
as column(subject_incidence, col[i]),
{Map Value( _rcOrig, {"", "Not Reported"}, Unmatched( _rcNow ) )},
Target Column( column(subject_incidence, col[i] ))
);
subject_incidence << End Data Update
)
);
這裡還有一種不同的方法來解決您的問題,即使用 Get RowsWhere() 來尋找沒有值的行,並將這些行值變更為“未報告”
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 ),
Try(
Column( subject_incidence, col[i] )[subject_incidence <<
get rows where( as Column( subject_incidence, col[i] ) == "" )] = "Not Reported"
)
)
);