-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMFALLINOUT.sas
258 lines (233 loc) · 7.52 KB
/
MFALLINOUT.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/**********************************************************************************************************************/
/* Macro MFALLINOUT */
/* Last updated: 10/21/2018 */
/* Last run: 10/21/2018 */
/* This SAS macro uses the concatenated MDS assessments and MedPAR fall claims to create two groups: */
/* 1) Patients who came from NH, this group fell during their nursing home stay */
/* 2) Patients who did not come from NH, this group fell outside of their nursing home stay */
/**********************************************************************************************************************/
dm 'log;clear;output;clear;';
%macro MFALLINOUT(daysin,daysout);
data claims_fallin(keep=
BENE_ID
SORTDT
AD_DGNS
BSF_AGE
BSF_CNTY_CD
BSF_CREC
BSF_DOB
BSF_DOD
BSF_OREC
BSF_RACE
BSF_RFRNC_YR
BSF_SEX
BSF_STATE_CD
BSF_ZIP
BSF_RTI
CVRLVLDT
D
DGNSCD1-DGNSCD25
DGNSECD1-DGNSECD12
DUAL_ELG_01-DUAL_ELG_12
DUAL_STUS_CD_01-DUAL_STUS_CD_12
DISQUALIFIED
DRG_CD
DXECODE_VALUE
DXINJURY_I
DXINJURY_VALUE
ECODE_I
ECODE_VALUE
ESRD_IND
FALL_IN
H_ADMSNDT
H_AGE_CNT
H_DSCHRGCD
H_DSCHRGDT
H_DSTNTNCD
H_PRVDRNUM
H_LOSCNT
HMO_IND_12
PREV_A2000
PREV_A2100
PREV_A0310F
PREV_M_TRGT_DT
R
SSLSSNF
primary_dx)
/*claims_fallout(keep=
BENE_ID
SORTDT
AD_DGNS
BSF_AGE
BSF_CNTY_CD
BSF_CREC
BSF_DOB
BSF_DOD
BSF_OREC
BSF_RACE
BSF_RFRNC_YR
BSF_SEX
BSF_STATE_CD
BSF_ZIP
BSF_RTI
CVRLVLDT
D
DGNSCD1-DGNSCD25
DGNSECD1-DGNSECD12
DUAL_ELG_01-DUAL_ELG_12
DUAL_STUS_CD_01-DUAL_STUS_CD_12
DISQUALIFIED
DRG_CD
DXECODE_VALUE
DXINJURY_I
DXINJURY_VALUE
ECODE_I
ECODE_VALUE
ESRD_IND
FALL_IN
H_ADMSNDT
H_AGE_CNT
H_DSCHRGCD
H_DSCHRGDT
H_DSTNTNCD
H_PRVDRNUM
H_LOSCNT
HMO_IND_12
PREV_A2000
PREV_A2100
PREV_A0310F
PREV_M_TRGT_DT
R
SSLSSNF
primary_dx)
dmds(drop=
AD_DGNS
BSF_AGE
BSF_CNTY_CD
BSF_CREC
BSF_DOB
BSF_DOD
BSF_OREC
BSF_RACE
BSF_RFRNC_YR
BSF_SEX
BSF_STATE_CD
BSF_ZIP
BSF_RTI
CVRLVLDT
D
DGNSCD1-DGNSCD25
DGNSECD1-DGNSECD12
DUAL_ELG_01-DUAL_ELG_12
DUAL_STUS_CD_01-DUAL_STUS_CD_12
DISQUALIFIED
DRG_CD
DXECODE_VALUE
DXINJURY_I
DXINJURY_VALUE
ECODE_I
ECODE_VALUE
ESRD_IND
FALL_IN
H_ADMSNDT
H_AGE_CNT
H_DSCHRGCD
H_DSCHRGDT
H_DSTNTNCD
H_PRVDRNUM
H_LOSCNT
HMO_IND_12
PREV_A2000
PREV_A2100
PREV_A0310F
PREV_M_TRGT_DT
SSLSSNF
primary_dx);
*/
set nhout.mdsclaims;
by bene_id;
length
r $1.
prev_a0310f $2.
prev_m_trgt_dt 4.
prev_A2000 4.
prev_A2100 $2.
fall_in 3.;
format
prev_m_trgt_dt
prev_a2000 date10.;
*look back from hospital claim at the previous MDS assessment and record their values;
prev_a0310f =lag(A0310F_ENTRY_DSCHRG_CD);
prev_m_trgt_dt =lag(M_TRGT_DT);
prev_a2000 =lag(A2000_DSCHRG_DT);
prev_a2100 =lag(A2100_DSCHRG_STUS_CD);
if first.bene_id then do;
prev_a0310f =" ";
prev_m_trgt_dt =.;
prev_a2000 =.;
prev_a2100 =" ";
end;
*create indicator r to distinguith whether the record is a MDS assessment or a fall claim;
label r="Indicator:M if MDS record, H if MedPAR record";
if m_prvdrnum ne " " then r="M";
else if h_prvdrnum ne " " then r="H";
if r="H" then do; *if this is a fall claim;
if first.bene_id then fall_in=0; *earliest hospital claim occurs before any NH assessment, patient does not come from NH;
else do;
if prev_a0310f in("10" "11","12") then do; *if there is a MDS assessment indicating discharge assessment right before the hospital claim;
if prev_a2100 not in("03" "09") then fall_in=0; *if for that discharge assessment, the patient does not go to 03=acute hospital, 09=long term care hospital;
else if prev_a2100 in("03" "09") then do; *if that discharge assessment indicates that the patient goes to 03=acute hospital, 09=long term care hospital;
d = h_admsndt - prev_a2000; *calculate the days since nh discharge to hospital admission;
if abs(d) <=&daysin. then fall_in=1; *if hospital admission date is within plus/minus 1 days of mds discharge date then this patient comes from NH;
else if abs(d) > &daysin. and abs(d)<=&daysout. then fall_in=-1;
else if abs(d) > &daysout. then fall_in=0; *if days elapsed greater than 180 then patients did not come from NH;
end;
end;
else do; *if previous MDS assessment looking back from fall claim is not a discharge assessment;
d=h_admsndt-prev_m_trgt_dt;
if abs(d) > &daysout. then fall_in=0; *if the more than 180 days has passed since NH discharge to hospital admission then patients did not come from NH;
end;
end;
end;
rename
A0310A_FED_OBRA_CD = A0310A
A0310B_PPS_CD = A0310B
A0310C_PPS_OMRA_CD = A0310C
A0310D_SB_CLNCL_CHG_CD = A0310D
A0310E_FIRST_SINCE_ADMSN_CD = A0310E
A0310F_ENTRY_DSCHRG_CD = A0310F
a1600_entry_dt = a1600
A1700_ENTRY_TYPE_CD = A1700
A1800_ENTRD_FROM_TXT = A1800
A2000_DSCHRG_DT = A2000
A2100_DSCHRG_STUS_CD = A2100
J1700A_FALL_30_DAY_CD = J1700A
J1700B_FALL_31_180_DAY_CD = J1700B
J1700C_FRCTR_SIX_MO_CD = J1700C
J1800_FALL_LAST_ASMT_CD = J1800
J1900A_FALL_NO_INJURY_CD = J1900A
J1900B_FALL_INJURY_CD = J1900B
J1900C_FALL_MAJ_INJURY_CD = J1900C;
if fall_in=1 then output claims_fallin;
else if fall_in=0 then output claims_fallout;
if r="M" then output dmds;
run;
*dmds contains mds assessments;
data dmds;
set dmds;
length prev_m_prvdrnum $12.;
prev_m_prvdrnum=lag(m_prvdrnum);
run;
data nhout.dmds;
set dmds;
run;
*claims_fallout contains fall claims from patients who fell outside of their nh stay;
data nhout.claims_fallout;
set claims_fallout;
run;
*claims_fallin contains fall claims from patients who fell during their nh stay;
data nhout.claims_fallin;
set claims_fallin;
run;
%mend MFALLINOUT;
%MFALLINOUT(1,180)