1
votes

I have a data set of patient information where I want to count how many patients (observations) have a given diagnostic code. I have 9 possible variables where it can be, in diag1, diag2... diag9. The code is V271. I cannot figure out how to do this with the "WHERE" clause or proc freq.

Any help would be appreciated!!

2
The caveat for the methods below is if a person can have multiple diagnostic codes that are equivalent to one condition which is found via multiple codes. This is more of a diagnostic coding/practice issue but I've seen it happen.Reeza

2 Answers

2
votes

Your basic strategy to this is to create a dataset that is not patient level, but one observation is one patient-diagnostic code (so up to 9 observations per patient). Something like this:

data want;
  set have;
  array diag[9];
  do _i = 1 to dim(diag);
    if not missing(diag[_i]) then do;
      diagnosis_Code = diag[_i];
      output;
    end;
  end;
  keep diagnosis_code patient_id [other variables you might want];
run;

You could then run a proc freq on the resulting dataset. You could also change the criteria from not missing to if diag[_i] = 'V271' then do; to get only V271s in the data.

1
votes

An alternate way to reshape the data that can match Joe's method is to use proc transpose like so.

proc transpose data=have out=want(keep=patient_id col1
                                  rename=(col1=diag)
                                  where=(diag is not missing));
  by patient_id;
  var diag1-diag9;
run;