我正在使用以下数据文件,其中包含每人多个记录和“临床事件结果”列中指定为1-5级的多个值-看起来像这样:
+--------+------------------------------------------------------------------------------+
| Pat_ID | Clinical Event Result |
+--------+------------------------------------------------------------------------------+
| 1 | Triage and Initial RN Assessment [level 1], Vital signs monitoring [level 3] |
| 1 | Trauma [Level 4], Consult/s (Social work, Psych, CXhild Life [Level 4] |
| 1 | Admission or O.R. preparation [level 5], |
| 2 | Triage and Initial RN Assessment only [level 1] |
| 2 | Oral Meds [level 1] |
+--------+------------------------------------------------------------------------------+
我正在寻求编写代码的建议,该代码将导致每Pat_ID
仅显示一条记录,从而在Clinical Event Result
中出现 level 时创建单个列柱。
例如,对于拥有Pat_ID=1
的个人,我希望输出显示为:
+---------+-----------+---------+---------+---------+---------+-----------+
| Pat_ID | Level 1 | Level 2 | Level 3 | Level 4 | Level 4 | Level 5 |
+---------+-----------+---------+---------+---------+---------+-----------+
| 1 | Triage... | null | Vitals | Trauma | CXLife | Admission |
+---------+-----------+---------+---------+---------+---------+-----------+
我认为首先我需要转置数据,以便每个病人行都有多个clinical event result
列,然后将这些列连接为一列。其次,解析每个级别,以便每个级别都有自己的列。
我一直在使用以下代码,但它仅获取clinical event result
列中的第一个值。例如,如果有两个level 4
事件,它将仅捕获第一个事件并将其放置在level 4
列中。
请注意,在查看此代码和上面的示例时,出于患者隐私的目的,我正在呼叫Financial_Number
PAT_ID
。
USE EMTCQIData
SELECT FCT.[Financial Number], FCT.[Clinical Event Result], FCT.Level_5, FCT.Level_4, FCT.Level_3, CPT.CPT, MAX_FCT.MAX_FCT_CHARGE
FROM CPT_MASTER as CPT
INNER JOIN
(
SELECT [Financial Number], [Clinical Event Result],
CASE
WHEN [Clinical Event Result] like '%1:1 Nursing care%' Then '1:1 Nursing Care'
WHEN [Clinical Event Result] like '%Admission or O.R. preparation%' Then 'Admission/OR Preparation'
WHEN [Clinical Event Result] like '%Airway Management (BLS/ALS interventions)%' Then 'Airway Management'
WHEN [Clinical Event Result] like '%Critical care transport preparation%' Then 'Critical care transport preparation'
WHEN [Clinical Event Result] like '%Medical/code alert%' Then 'Medical/code alert'
WHEN [Clinical Event Result] like '%O2 therapy%' Then 'O2 therapy'
WHEN [Clinical Event Result] like '%Pain management with reassessment%' Then 'Pain management with reassessment'
WHEN [Clinical Event Result] like '%Respiratory monitoring%' Then 'Respiratory monitoring'
END Level_5,
CASE
WHEN [Clinical Event Result] like '%Respiratory assessment%' Then 'Respiratory assessment'
WHEN [Clinical Event Result] like '%Patient transport X-ray/CT%' Then 'Patient transport X-ray/CT'
WHEN [Clinical Event Result] like '%Pulse oximetery%' Then 'Pulse oximetery'
WHEN [Clinical Event Result] like '%Cardiac monitoring%' Then 'Cardiac monitoring'
WHEN [Clinical Event Result] like '%Neurological monitoring%' Then 'Neurological monitoring'
WHEN [Clinical Event Result] like '%Wound Care (less than 15 min)%' Then 'Wound Care (less than 15 min)'
END Level_4,
CASE
WHEN [Clinical Event Result] like '%Blood-peripheral venous%' Then 'Blood-peripheral venous'
WHEN [Clinical Event Result] like '%Urine-catheterized%' Then 'Urine-catheterized'
WHEN [Clinical Event Result] like '%Oral hydration interventions%' Then 'Oral hydration interventions'
WHEN [Clinical Event Result] like '%Oral meds%' Then 'Oral meds'
WHEN [Clinical Event Result] like '%Medication teaching%' Then 'Medication teaching'
WHEN [Clinical Event Result] like '%Vital signs monitoring%' Then 'Vital signs monitoring'
END Level_3
FROM ED_FCT_Q1_FY19
)
as FCT ON FCT.[Financial Number]=CPT.FIN
INNER JOIN
(
SELECT [Financial Number] as Fin, MAX(Charge_Code) as MAX_FCT_CHARGE
FROM ED_FCT_Q1_FY19
GROUP BY [Financial Number]
) as MAX_FCT on CPT.Fin = MAX_FCT.Fin
WHERE (FCT.[Clinical Event Result] like '%Level%' or FCT.[Clinical Event Result] like '%level%') AND CPT.CPT LIKE '9928%'
答案 0 :(得分:2)
以下代码在SAS中
data clinical;
length event_res /*level1 level2 level3 level4 level5*/ $100.;
input pat_id 1. event_res &;
datalines;
1|Triage and Initial RN Assessment [level 1], Vital signs monitoring [level 3]|
1|Trauma [Level 4], Consult/s (Social work, Psych, CXhild Life [Level 4]
1|Admission or O.R. preparation [level 5],
2|Triage and Initial RN Assessment only [level 1]
2| Oral Meds [level 1]
;
run;
proc sort data=clinical; by pat_id; run;
data clinical1;
length str $300;
set clinical;
by pat_id;
retain str "";
if first.pat_id then str=event_res; /*For Every first entry of a PAT_ID, the string is the first available Event Result and for next entries it is concatenated*/
else str=catx('@',str,event_res); /*Concatenate String and use @ or any other symbol to identify the Levels*/
str=TRANWRD(str,'],',']@') ; /*Convert/transalte ], into ]@ just to better differentiate the Levels*/
if last.pat_id; /*Keep only the the Last entry per Pat_Id after concatenation, because at last entry we will have full combined string*/
/*Add @ at begin and end to mark the boundaries*/
str="@"||str;
if substr(str,length(str),1) ne "@" then str1=str||"@";
else str1=str;
cnt=count(str1,'@');
drop event_res str;
run;
proc sql noprint;
select max(cnt)-1 into: max_cnt from clinical1;
quit;
%let max_cnt1=&max_cnt;
data clinical2;
set clinical1;
/*Define array of variables*/
array vars{&max_cnt1} $100. var_1-var_&max_cnt1;
i=1;
do while (i<=cnt-1);
vars{i}=scan(str1,i,'@');
i=i+1;
end;
array level{5} $100. lvl_1-lvl_5;
do i = 1 to 5;
if find(upcase(vars{i}),"LEVEL 1")>0 then level{1}=catx('#',level{1},vars{i});
if find(upcase(vars{i}),"LEVEL 2")>0 then level{2}=catx('#',level{2},vars{i});
if find(upcase(vars{i}),"LEVEL 3")>0 then level{3}=catx('#',level{3},vars{i});
if find(upcase(vars{i}),"LEVEL 4")>0 then level{4}=catx('#',level{4},vars{i});
if find(upcase(vars{i}),"LEVEL 5")>0 then level{5}=catx('#',level{5},vars{i});
end;
drop cnt var_1 var_2 var_3 var_4 var_5 i;
run;