在SAS中(通过WPS Workbench),我尝试使用popn字段(填充为整数)作为权重来获取数据的频率计数。
proc freq data= working.PC_pops noprint;
by District;
weight popn / zeros;
tables AreaType / out= _AreaType;
run;
但是,当我运行上面的代码时,出现以下错误,指向我的Weight语句:
ERROR: Found "/" when expecting ;
ERROR: Statement "/" is not valid
我已经在线检查了语法,并在权重中包括零计数,它肯定说在Weight语句中使用“ / zeros”选项,但是SAS(WPS)出错了吗?我在做什么错了?
更新:我现在发现WPS Workbench不支持zeros选项。有解决方法吗?
答案 0 :(得分:-1)
鉴于您没有使用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集,该集的hacky要少一些,但是我不确定在非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;