SAS:在Proc Freq命令错误中使用权重语句



在SAS中(通过WPS Workbench),我试图使用POPN字段(群体作为整数)作为权重来获得一些频率计数。

proc freq data= working.PC_pops noprint; 
    by District;
    weight popn / zeros; 
    tables AreaType / out= _AreaType;
run;

但是,当我运行上面的代码时,我会收到以下错误指向我的权重语句:

ERROR: Found "/" when expecting ;
ERROR: Statement "/" is not valid

我已经在线检查了语法并在我的加权中包括零计数,它肯定说在权重语句中使用"/zeros"选项,但是SAS(WPS)是错误的吗?我在做什么错?

更新:我现在发现WPS Workbench不支持零选项。有解决方法吗?

鉴于您没有使用PROC FREQ(统计测试)的任何高级元素,因此使用PROC TABULATE可能会更好。这将使您使用一些不同的方法准确地定义输出中想要的级别,即使它们的元素为零元素。这是一个有点刺的解决方案,但它起作用(至少在SAS 9.4中):

data class;
  set sashelp.class;
  weight=1;
  if age=15 then weight=0;
run;
proc freq data=class;
  weight weight/zeros;
  tables age;
run;

proc tabulate data=class;
  class age;
  var weight;
  weight weight; *note this is WEIGHT, but does not act like weight in PROC FREQ, so we have to hack it a bit by using it as an analysis variable which is annoying;
  tables age,sumwgt='Count'*weight=' '*f=2.0;
run;

都给出相同的结果。您也可以使用classData集,这有点少一些,但是我不确定它在非SAS中得到了支持:

proc sort data=class out=class_classdata(keep=age) nodupkey;
  by age;
run;
proc tabulate data=class classdata=class_classdata;
  class age;
  freq weight;  *note this is FREQ not WEIGHT;
  tables age,n*f=2.0/misstext='0';
run;

最新更新