Frequency of a value across multiple variables?

谁都会走 提交于 2019-12-12 23:35:21

问题


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


回答1:


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.




回答2:


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;


来源:https://stackoverflow.com/questions/28439907/frequency-of-a-value-across-multiple-variables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!