I have a list of diagnosis codes, and I want to flag if any of those codes exist anywhere in 15 different diagnosis variables. I created a series of IF-THEN statements, but I have many such lists of DX codes and an array is a more efficient approach. However, the array is only flagging a very small percentage of cases that should be flagged (I confirmed this by manually searching the data file). The cases that it does flag hit on various DX variables (DX1, DX3, DX12, etc), so it's not like the array is only searching DX15 or something like that.
%let PTB_all_list = ("O6010X","O6012X","Z3A22","Z3A23","Z3A24","Z3A25","Z3A26","Z3A27","O6013X",
"O6014X","Z3A28","Z3A29","Z3A30","Z3A31","Z3A32","Z3A33","Z3A34","Z3A35",
"Z3A36");
DATA want; SET have;
ARRAY dx_codes DX1-DX15;
do index=1 to dim(dx_codes );
IF dx_codes[index] in: (&PTB_all_list.) THEN PTB_birth_array=1; ELSE PTB_birth_array=0;
end;
IF (DX1 in (&PTB_all_list.) OR
DX2 in (&PTB_all_list.) OR
DX3 in (&PTB_all_list.) OR
DX4 in (&PTB_all_list.) OR
DX5 in (&PTB_all_list.) OR
DX6 in (&PTB_all_list.) OR
DX7 in (&PTB_all_list.) OR
DX8 in (&PTB_all_list.) OR
DX9 in (&PTB_all_list.) OR
DX10 in (&PTB_all_list.) OR
DX11 in (&PTB_all_list.) OR
DX12 in (&PTB_all_list.) OR
DX13 in (&PTB_all_list.) OR
DX14 in (&PTB_all_list.) OR
DX15 in (&PTB_all_list.)) THEN PTB_birth_line=1; ELSE PTB_birth_line=0;
RUN;
title1 "PTB";
PROC FREQ data=want;
TABLES PTB_birth_array PTB_birth_line; RUN;
And here are the frequencies:
... View more