【发布时间】:2019-05-11 09:55:12
【问题描述】:
我想在 SAS 中创建一个单独的列,用于汇总数据集中每个人的几列。数据如下所示:
Subject VisitNumber Exam Result Comments
001 1 Blood Negative Will return for more testing
001 1 BP 100 Score is in normal range
001 1 Vision 20/20 No issues with eyesight
002 5 BMI 19 Within healthy range
002 5 Hearing Good Patient hears well
002 5 Drug Negative Subject passed drug test
每个受试者的信息及其后续访问次数应总结如下:
Subject VisitNumber Summary
001 1 Exam: Blood, Result: Negative, Comments: Will return for more testing; Exam: BP, Result: 100, Comments: Score is normal range; Exam: Vision, Result: 20/20, Comments: No issues with eyesight
002 5 Exam: BMI, Result: 19, Comments: Within healthy range; Exam: Hearing, Result: Good, Comments: Patient hears well; Exam: Drug, Result: Negative, Comments: Subject passed drug test
可以通过以下方式在 R 中执行此操作:
for (i in 1:length(data$Subject))
{
data$Summary[i] = data$Comments[i] = 'Exam: ' + Exam[i] + ', Result: ' + Result[i] + ', Comments: ' + Comments[i] + '; '
}
然后可以通过 Comments 列逐行压缩数据。任何关于如何通过 SAS 中的 DATA 或 PROC SQL 步骤完成此操作的见解将不胜感激。
【问题讨论】: