sas - SAS:在 Proc Freq 命令错误中使用 Weight 语句
问题描述
在 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 选项。有解决方法吗?
解决方案
鉴于您没有使用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;
推荐阅读
- rust - 如何共享 Arc
>? - javascript - 我的 jquery 代码在 ejs 模板中不起作用
- javascript - 如何在提要html中附加评论使用jquery
- sql - Sequelize - 在种子后重置自动增量:撤消:全部
- django - ufw 禁止 docker 容器连接到 postgres
- python - 使用 python 初学者级别的网页抓取
- android - 重载分辨率歧义。所有这些功能都匹配。在毕加索(入)功能
- python - 在python中将值从列表添加到字典
- python - 熊猫,从日期列创建缺少的日期字典
- unit-testing - unittest 异步模拟不适用于 pytest?