-
Notifications
You must be signed in to change notification settings - Fork 0
/
MDSCHRG.sas
330 lines (294 loc) · 9.53 KB
/
MDSCHRG.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/**************************************************************************************************************************/
/* Macro MDSCHRG */
/* Last updated: 10/21/2018; */
/* Last Run: 10/21/2018; */
/* This SAS macro performs the following: */
/* 1) create deminominators for those who went back to nursing home versus those who did not go back */
/* **for those who went back, obtain their post hospitalization mds assessments */
/* **for those who did not go back, obtain their hospital claims to count the number of fall episodes for the flowchart*/
/* 2) create denominators for those who went back to same nusing home vs those who went back to different nursing home */
/* **for those who went back to same nursing home, obtain their pre- and post- hospitalization mds assessments */
/* **store those mds assessments in two datasets mdspre_same_nh and mdspost_same_nh */
/* **for those who went back to different nursing home, obtain their post- hospitalization mds assessments */
/* **store those mds assessments in mdspost_different_nh */
/**************************************************************************************************************************/
dm 'log;clear;output;clear;';
%macro MDSCHRG;
data nhout.mds_claims_fallin;
set nhout.mds_claims_fallin;
prev_r=lag(r);
prev_uniqueid=lag(uniqueid);
run;
*separate patients who went back to NH versus those who did not;
*for patietns who went back to nh, separate their mds assessment before hospitalization and after;
data getpre_mds_fallin_back(keep=bene_id prev_uniqueid get_n_claims_mds)
getpost_mds_fallin_back(keep=bene_id prev_uniqueid get_n_claims_mds);
set nhout.mds_claims_fallin;
by bene_id;
if not first.bene_id then do;
if r="M" and prev_r="H" then do;
get_n_claims_mds=n_claims_mds-2;
output getpre_mds_fallin_back;
get_n_claims_mds=n_claims_mds;
output getpost_mds_fallin_back;
get_n_claims_mds=n_claims_mds+1;
output getpost_mds_fallin_back;
get_n_claims_mds=n_claims_mds+2;
output getpost_mds_fallin_back;
end;
end;
run;
data getpost_mds_fallin_back(rename=(prev_uniqueid=uniqueid));
set getpost_mds_fallin_back;
run;
data getpre_mds_fallin_back(rename=(prev_uniqueid=uniqueid));
set getpre_mds_fallin_back;
run;
*for those who did not go back, obtain their hospital claims;
*checked that these are indeed all hospital claims;
data nhout.claims_fallin_notback(keep=bene_id uniqueid n_claims_mds h_admsndt);
set nhout.mds_claims_fallin;
by bene_id;
if last.bene_id and r="H" then do;
output nhout.claims_fallin_notback;
end;
run;
*get mds assessments before hospitalization for those who went back to nh;
proc sql;
create table mdspre_back as select
P.*,
M.*
from getpre_mds_fallin_back as P,
nhout.mds_claims_fallin(drop=
AD_DGNS
uniqueid
BSF_AGE
BSF_CNTY_CD
BSF_CREC
BSF_DOB
BSF_DOD
BSF_OREC
BSF_RTI
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
SORTDT
HHH
NEXT_H_ADMSNDT
NEXT_H_DSCHRGDT
REMOVEHHH) as M
where (P.BENE_ID = M.BENE_ID and P.GET_N_CLAIMS_MDS = M.N_CLAIMS_MDS);
quit;
*get mds assessments after hospitalization for those who went back to nh;
proc sql;
create table mdspost_back as select
PO.*,
M.*
from getpost_mds_fallin_back as PO,
nhout.mds_claims_fallin(drop=
uniqueid
AD_DGNS
BSF_AGE
BSF_CNTY_CD
BSF_CREC
BSF_DOB
BSF_DOD
BSF_OREC
BSF_RACE
BSF_RTI
BSF_RFRNC_YR
BSF_SEX
BSF_STATE_CD
BSF_ZIP
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
SORTDT
HHH
NEXT_H_ADMSNDT
NEXT_H_DSCHRGDT
REMOVEHHH) as M
where (PO.BENE_ID = M.BENE_ID and PO.GET_N_CLAIMS_MDS = M.N_CLAIMS_MDS);
quit;
data nhout.mdspre_back;
set mdspre_back;
run;
*checked that the post mds assessments selected that having missing discharge dates are hospital claims;
*this happens when the patient had two fall claims and in between there are less than 3 MDS assessments;
*delete those hospital claims because we only want post hospitalization mds assessments;
data nhout.mdspost_back;
set mdspost_back;
if m_trgt_dt^=.;
run;
*sanity check:there are same number of fall episodes in pre-hospitalization mds assessments
*as the number of fall episodes in post-hospitalization mds assessments if we just include the first one after hospitalization;
/*
data sanity_check;
set nhout.mdspost_back;
by uniqueid;
if first.uniqueid;
run;
*/
*Separate patients who came from NH who went back to same/different NH after hospitalization;
*checked that no missing m_prvdrnum or prev_m_prvdrnum in dataset mdspost_back;
data _getmdspost_different_NH (keep=bene_id uniqueid _n_claims_mds)
_getmdspost_same_NH (keep=bene_id uniqueid _n_claims_mds)
_getmdspre_same_NH (keep=bene_id uniqueid _n_claims_mds);
set nhout.mdspost_back;
by uniqueid;
if first.uniqueid then do;
if prev_m_prvdrnum ne m_prvdrnum then do;
_n_claims_mds=get_n_claims_mds;
output _getmdspost_different_NH;
_n_claims_mds=get_n_claims_mds+1;
output _getmdspost_different_NH;
_n_claims_mds=get_n_claims_mds+2;
output _getmdspost_different_NH;
end;
else if prev_m_prvdrnum=m_prvdrnum then do;
_n_claims_mds=get_n_claims_mds-2;
output _getmdspre_same_NH;
_n_claims_mds=get_n_claims_mds;
output _getmdspost_same_NH;
_n_claims_mds=get_n_claims_mds+1;
output _getmdspost_same_NH;
_n_claims_mds=get_n_claims_mds+2;
output _getmdspost_same_NH;
end;
end;
run;
*get mds assessments after hospitalization for patients who went back to different nh;
proc sql;
create table nhout.mdspost_different_nh as select
PO.*,
M.*
from _getmdspost_different_nh as PO,
nhout.mdspost_back (drop=uniqueid) as M
where (PO.bene_id = M.bene_id and PO._N_CLAIMS_MDS = M.GET_N_CLAIMS_MDS);
quit;
*get mds assessments after hospitalization for patients who went back to same nh;
proc sql;
create table nhout.mdspost_same_nh as select
PO.*,
M.*
from _getmdspost_same_nh as PO,
nhout.mdspost_back(drop=uniqueid) as M
where (PO.bene_id= M.bene_id and PO._N_CLAIMS_MDS = M.GET_N_CLAIMS_MDS);
quit;
*get mds assessments before hospitalization for patients who went back to same nh;
proc sql;
create table nhout.mdspre_same_nh as select
PO.*,
M.*
from _getmdspre_same_nh as PO,
nhout.mds_claims_fallin(drop=
uniqueid
AD_DGNS
BSF_AGE
BSF_CNTY_CD
BSF_CREC
BSF_DOB
BSF_DOD
BSF_OREC
BSF_RACE
BSF_RTI
BSF_RFRNC_YR
BSF_SEX
BSF_STATE_CD
BSF_ZIP
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
SORTDT
HHH
NEXT_H_ADMSNDT
NEXT_H_DSCHRGDT
REMOVEHHH
DUAL_ELGBL_MONS) as M
where (PO.bene_id = M.bene_id and PO._N_CLAIMS_MDS = M.N_CLAIMS_MDS);
quit;
%mend MDSCHRG;