BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chuakp
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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;

--
Paige Miller
chuakp
Obsidian | Level 7

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.

data_null__
Jade | Level 19

WHICHC function might be acceptable.

array dx

  • dx_code:;
  • f1=whichC('0199',of DX

  • );
  • f2=whichC('7806',of DX

  • );
  • ...

    flag = max(f1,f2,f3,f4);

    hackathon24-white-horiz.png

    2025 SAS Hackathon: There is still time!

    Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

    Register Now

    How to Concatenate Values

    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.

    SAS Training: Just a Click Away

     Ready to level-up your skills? Choose your own adventure.

    Browse our catalog!

    Discussion stats
    • 3 replies
    • 2245 views
    • 0 likes
    • 3 in conversation