簡體   English   中英

SAS:在Proc Freq命令錯誤中使用Weight語句

[英]SAS: Using Weight statement in a Proc Freq command error

在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選項。 有沒有解決方法?

鑒於您沒有使用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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM