lrk889
lrk889

Reputation: 119

Frequency of a value across multiple variables?

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!!

Upvotes: 1

Views: 853

Answers (2)

DWal
DWal

Reputation: 2762

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;

Upvotes: 1

Joe
Joe

Reputation: 63434

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.

Upvotes: 2

Related Questions