DATA Step, Macro, Functions and more

Find multiple ICD 9/10 codes over multiple diagnosis variables

Reply
Learner
Posts: 1

Find multiple ICD 9/10 codes over multiple diagnosis variables

Hi, I am a long time STATA user who is required to use SAS for a certain project.

 

How can I search for a list of 20 diagnosis codes over 25 diagnosis variables (diag1-diag25) and have it flag a new variable as one?

 

This would be similar to the STATA code:

 

local diagcode

"xxxxx"

"xxxxx"

"xxxxx"

 

foreach x of varlist diag1-diag25 {

replace diabetes = 1 if `x' == diagcode

 

Thank you!

Respected Advisor
Posts: 4,566

Re: Find multiple ICD 9/10 codes over multiple diagnosis variables

[ Edited ]

@atex

Please always post sample data in form of a data step and then show us the desired result. This helps us to better understand what you have and also test our code against your sample.

 

List-processing is "better" implemented in other languages. Below code does what you're after if I've understood your Stata code correctly.

data have;  
  array diag {25} $10 (25*'other code');
  output;
  diag4='code3';
  diag15='code2';
  output;
run;


proc format;
  invalue diagcode
    'code1'=1
    'code2'=1
    'code3'=1
  ;
run;

data want;
  flag=0;
  set have;
  array diags {*} diag:;
  do _i=1 to dim(diags);
    if input(diags[_i],diagcode.)=1 then
      do;
        flag=1;
        leave;
      end;
  end;
run;

 

Super User
Posts: 13,084

Re: Find multiple ICD 9/10 codes over multiple diagnosis variables

What does "it flag a new variable as one" actually mean?

 

WHICHN or WHICHC (depending on whether your diagnosis variables and diagnosis codes are numeric or character) may work.

A brief example of what I think you are doing. Diag holds the diagnosis codes, the array c has the code values you are looking for and the array f has variable that hold flag values of 1 or 0 for found.

data work.example;
   informat diag1 - diag3 $2.;
   input diag1 - diag3 ;
   array d diag: ;
   /* this holds the values of the codes to search for*/
   array c (4) $ 2 _temporary_ ('Ab','Ac','Ba','Bb');
   /* and results size should match array c*/
   array f Ab Ac Ba Bb;
   do i=1 to dim(c);
      f[i]=whichc(c[i],of d(*))>0;
   end;

datalines;
Ab Ac Ad
Ac Ac Ae
Ba Bb Bc
Bb Bb Bb
;
   
run;
Ask a Question
Discussion stats
  • 2 replies
  • 166 views
  • 0 likes
  • 3 in conversation