列出频率为零的变量-Proc Freq或Proc制表

时间:2019-07-12 12:12:56

标签: sas

我正在选择一组邮政编码,通过一个2比2的表格按年龄组列出频率计数。我想列出频率计数为零的邮政编码,以便整个选定的邮政编码组以及年龄组(可能有5个年龄组)的所有可能组合出现在最终表中。

这是我使用Proc Freq尝试的代码。目前,这仍未列出所有可能的组合。

proc freq data = join;
where group_1 = 1 and ZIP in ('20814' '20815' '20816' '20817' '20832' 
'20850' '20851' '20852' '20853' '20866') and Race_n = 'NH-Black';
tables ZIP*agegrp / nocol norow nopercent sparse list;
title "Disease Mortality Counts 2016 By Race";
run;

1 个答案:

答案 0 :(得分:2)

Proc TABULATE

您需要一个classdata表,其中列出了类组合的所有可能值。

例如:

data all_ages;
  do age = 18 to 65;
    output;
  end;
run;

data patients;
  do patid = 1 to 10000;
    do until (age not in (19, 23, 29, 31, 37, 41, 43,  47, 53, 59));
      age = 18 + int((65-17) *ranuni(123));
    end;
    output;
  end;
run;

proc format;
  value misszero .=0 other=[best12.];

proc tabulate data=patients classdata=all_ages;
  class age ;
  table age, n*f=misszero.;
run;

enter image description here

执行频率

用classdata修改数据,并为classdata项分配零权重。在weight语句中允许零作为权重。

data patients_v;
  set
    patients
    all_ages (in=zero)
  ;
  unity = 1 - zero;
run;

proc freq data=patients_v;
  table age;
  weight unity / zeros ;
run;