在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我已经在线检查了语法,并在我的权重中包括零计数,它明确地表明在权重语句中使用"/ zeros“选项,但SAS (WPS)是错误的?我做错了什么?
更新:我现在发现WPS Workbench不支持zeros选项。有什么解决方法吗?
发布于 2018-12-18 05:53:14
如果您没有使用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 set,它不那么复杂,但我不确定它在非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;https://stackoverflow.com/questions/53819629
复制相似问题