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);

    sas-innovate-2024.png

    Don't miss out on SAS Innovate - Register now for the FREE Livestream!

    Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

     

    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.

    Click image to register for webinarClick image to register for webinar

    Classroom Training Available!

    Select SAS Training centers are offering in-person courses. View upcoming courses for:

    View all other training opportunities.

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