Desktop productivity for business analysts and programmers

Counting within an ARRAY in DATA steps (adding across a single observation)

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

Counting within an ARRAY in DATA steps (adding across a single observation)

I am currently attempting to use a number of different definitions to identify cancer cases in claims data.  In this definition, I would like to require that TWO OR MORE of the diagnosis fields (dx1 - dx15) be related to cancer. 

I have been using a simple array to identify when ONE OR MORE of the dx fields were related to cancer:

ARRAY surgINdx(15) $ dx1-dx15;

  DO r=1 to 15;

  IF surgINdx(r) IN("162%" "2312%")

  THEN rDX=1;

  ELSE rDX = 0;

END;

RUN;

My question is this: how can I command my output variable rDX to be a count of the number of dx fields that were cancer related, rather than identifying if any of them were cancer related?

I was hoping to use the code below but for some reason, everybody ends up with rDX = 0.  I figured I'd preset all rDX to 0, then add 1 each time that dx1 through dx15 is a cancer related code.  Can somebody point out to me what is wrong?  The log looks good.  No errors or anything.

  *INPATIENT*;

DATA hw3.lungSURGin;

  SET all_inclaims;

  rDX=0;

  ARRAY surgINdx(15) $ dx1-dx15;

  DO r=1 to 15;

  IF surgINdx(r) IN("162%" "2312%")

  THEN rDX+1;

  ELSE rDX+0;

  END;

  RUN;

*REGARDLESS OF WHETHER I USE PROC SQL OR PROC PRINT, THERE ARE NO OBSERVATIONS WHERE rDX > 1*;

PROC SQL;

select count(distinct enrolid) as cases_surgIN

from hw3.lungSURGin

WHERE rdx > 1;

QUIT;

RUN;

PROC PRINT DATA=hw3.lungSURGin (OBS=100);

WHERE rDX>1;

RUN;


Accepted Solutions
Solution
‎02-27-2013 12:41 AM
Super User
Super User
Posts: 6,351

Re: Counting within an ARRAY in DATA steps (adding across a single observation)

First your IF condition looks wrong.  Are you thinking that the percent sign is going to be treated like a wildcard?

Perhaps you want to use the : modifier on the IN operator instead.  This will allow DX codes like '1621' to match.

rdx=0;

array surgindx dx1-dx15;

do r=1 to dim(surgindx);

  if surgindx(r) in: ('162' '2312') then rdx+1;

end;

View solution in original post


All Replies
Contributor
Posts: 50

Re: Counting within an ARRAY in DATA steps (adding across a single observation)

My numbers are really low.  I'm starting to wonder if the coding is actually right and there are just no cases that meet my definition...

Solution
‎02-27-2013 12:41 AM
Super User
Super User
Posts: 6,351

Re: Counting within an ARRAY in DATA steps (adding across a single observation)

First your IF condition looks wrong.  Are you thinking that the percent sign is going to be treated like a wildcard?

Perhaps you want to use the : modifier on the IN operator instead.  This will allow DX codes like '1621' to match.

rdx=0;

array surgindx dx1-dx15;

do r=1 to dim(surgindx);

  if surgindx(r) in: ('162' '2312') then rdx+1;

end;

New Contributor
Posts: 3

Re: Counting within an ARRAY in DATA steps (adding across a single observation)

mconover, I also work in the health care industry (health insurance) and frequently have to run reports populated by summarized data similar to what you are trying to do here. However, I only use Enterprise Guide and the query builder tool as I am not yet very familiar with the SAS code syntax (I am a programmer at heart but haven't learned the SAS ropes yet).

I think that the code Tom posted should work just fine, but if you are interested in building this utilizing the EG query builder consider using a case statement to populated a calculated column:

CASE WHEN t1.surgindx LIKE '162' OR LIKE '2312' THEN 1

           ELSE 0

END

Once you create this calculated column drag it into the selected column area in the query builder and SUM the field. The output should be a count of every claim that is related to cancer. If you do not sum the calculated column then the output will just be a list of flags (also useful sometimes depending on your situation).

I hope this helps!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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