Hello - I'm analyzing a healthcare claims database with one row per discharge. Each row has 41 variables representing 41 discharge diagnosis codes (variables dx_code1-dx_code41). I am trying to identify all discharges with one of four diagnosis codes. I could manually type this out but I'm sure there must be a more elegant way (macro?) to do this. Any help would be appreciated. Thanks!
data discharges;
where
dx_code1 in: ('0199', '7806', '78034', '7213') or
dx_code2 in: ('0199', '7806', '78034', '7213') or
...
dx_code41 in: ('0199', '7806', '78034', '7213');
run;
Maybe an ARRAY would work
Something like
/* UNTESTED CODE */
data discharges;
set whatever;
array dx dx_code1-dx_code41;
flag=0;
do i=1 to dim(dx);
if dx(i) in ('0199', '7806', '78034', '7213') then flag=flag+1;
end;
if flag>0 then output;
run;
Maybe an ARRAY would work
Something like
/* UNTESTED CODE */
data discharges;
set whatever;
array dx dx_code1-dx_code41;
flag=0;
do i=1 to dim(dx);
if dx(i) in ('0199', '7806', '78034', '7213') then flag=flag+1;
end;
if flag>0 then output;
run;
Thanks - just needed to be a colon after "in." Also, I don't think you need the flag = flag + 1 per se; I was able to get it to work just by doing:
if dx(i) in: ('0199', '7806', '78034', '7213') then flag=1;
I appreciate your help.
WHICHC function might be acceptable.
array dx
f1=whichC('0199',of DX
f2=whichC('7806',of DX
...
flag = max(f1,f2,f3,f4);
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.