我有一个临床测试结果的数据集。我想基于患者阳性的测试的变量名称创建一个“结果”变量。许多if-else语句可以解决这个问题,但是我希望能够构建一个字符变量来说明多个测试结果,而不必先验地了解各种响应模式。
这是数据集的示例:
ID RSV FLU
1 Positive Negative
2 Negative Positive
3 Negative Negative
4 Positive Positive
5 Negative Negative
这就是我要寻找的:
ID RSV FLU Result
1 Positive Negative RSV
2 Negative Positive FLU
3 Negative Negative
4 Positive Positive RSV, FLU
5 Negative Negative
任何帮助将不胜感激!
答案 0 :(得分:1)
我已经使用proc转置来反转数据集,通过这种方法,您可以根据临床测试结果需要拥有尽可能多的列
/*Input Dataset*/
data have;
input ID RSV$ FLU$;
datalines;
1 Positive Negative
2 Negative Positive
3 Negative Negative
4 Positive Positive
5 Negative Negative
;
run;
proc sort data=have; by id; run;
/*Initial Transpose*/
proc transpose data=have out=want0;
by id;
var rsv flu;
run;
/*Manipulate transposed dataset*/
data want1;
length Result $50.;
set want0;
by id;
retain Result '';
if first.id then Result='';
if first.id and col1='Positive' then Result=_NAME_;
else if not first.id and col1='Positive' then Result=catx(', ',Result,_NAME_);
if last.id;
run;
/*Final outcome*/
proc sql;
create table want
as
select a.*, b.result
from have a
left join want1 b
on a.id=b.id;
quit;
答案 1 :(得分:0)
在这里,数组和VNAME()可能是不错的选择。未经测试。
subresource_uris