sas proc 制表(频率)
sas proc tabulate (freq)
我有以下问题:
一些示例数据:
data;
input id article sex count;
datalines;
1 139 1 2
2 139 2 2
3 146 2 1
4 146 2 2
5 146 1 0
6 111 2 10
6 111 1 1
;
run;
现在,我有这个代码:
proc tabulate;
freq count;
class article sex;
table article, sex /misstext='0';
run;
和下面的代码相比有什么区别吗?
proc tabulate;
var count;
class article sex;
table article, sex*count;
run;
或者它是否做同样的事情?哪一个值得推荐?
注意两个 tabulate
变体的 运行 产生的输出。
对于手头的数据集,结果是相同的,只是呈现方式不同。
- 第一个有性别 class 单元格,这些单元格是隐式频率 (
N
) 计算,count
加权,也隐式格式化为整数。 implicits 是在没有其他语句和选项的情况下的默认行为。
- 第二个有性别 class 个单元格,它们是
count
的计算总和,格式为默认的 2 位小数。
如果数据集在 table
中使用了额外的 var
变量,要执行的统计计算以及加权的作用将取决于您所做的演示的性质和观众消费它。您可能希望或不希望 'count' 影响统计计算的频率加权。
询问 5 个人的推荐,你可能会得到 6!
从联机文档中,将 FREQ
语句的详细信息与 WEIGHT
语句进行比较:
Required Argument
variable
- specifies a numeric variable whose value represents the frequency of the observation. If you use the FREQ statement, then the procedure assumes that each observation represents n observations, where n is the value of variable. If n is not an integer, then SAS truncates it. If n is less than 1 or is missing, then the procedure does not use that observation to calculate statistics.
- The sum of the frequency variable represents the total number of observations.
和
Required Argument
variable
- specifies a numeric variable whose values weight the values of the analysis variables. The values of the variable do not have to be integers. PROC TABULATE responds to weight values in accordance with the following table.
0
: Counts the observation in the total number of observations
<0
: Converts the value to zero and counts the observation in the total number of observations
.missing
: Excludes the observation
To exclude observations that contain negative and zero weights from the analysis, use EXCLNPWGT. Note that most SAS/STAT procedures, such as PROC GLM, exclude negative and zero weights by default.
Note: Prior to Version 7 of SAS, the procedure did not exclude the observations with missing weights from the count of observations.
Restrictions
- To compute weighted quantiles, use QMETHOD=OS in the PROC statement.
- PROC TABULATE will not compute MODE when a weight variable is active. Instead, try using PROC UNIVARIATE when MODE needs to be computed and a weight variable is active.
Interaction
- If you use the WEIGHT= option in a VAR statement to specify a weight variable, then PROC TABULATE uses this variable instead to weight those VAR statement variables.
Tip
- When you use the WEIGHT statement, consider which value of the VARDEF= option is appropriate. See the discussion of VARDEF=divisor and the calculation of weighted statistics in the Keywords and Formulas section of this document.
我有以下问题:
一些示例数据:
data;
input id article sex count;
datalines;
1 139 1 2
2 139 2 2
3 146 2 1
4 146 2 2
5 146 1 0
6 111 2 10
6 111 1 1
;
run;
现在,我有这个代码:
proc tabulate;
freq count;
class article sex;
table article, sex /misstext='0';
run;
和下面的代码相比有什么区别吗?
proc tabulate;
var count;
class article sex;
table article, sex*count;
run;
或者它是否做同样的事情?哪一个值得推荐?
注意两个 tabulate
变体的 运行 产生的输出。
对于手头的数据集,结果是相同的,只是呈现方式不同。
- 第一个有性别 class 单元格,这些单元格是隐式频率 (
N
) 计算,count
加权,也隐式格式化为整数。 implicits 是在没有其他语句和选项的情况下的默认行为。 - 第二个有性别 class 个单元格,它们是
count
的计算总和,格式为默认的 2 位小数。
如果数据集在 table
中使用了额外的 var
变量,要执行的统计计算以及加权的作用将取决于您所做的演示的性质和观众消费它。您可能希望或不希望 'count' 影响统计计算的频率加权。
询问 5 个人的推荐,你可能会得到 6!
从联机文档中,将 FREQ
语句的详细信息与 WEIGHT
语句进行比较:
Required Argument
variable
- specifies a numeric variable whose value represents the frequency of the observation. If you use the FREQ statement, then the procedure assumes that each observation represents n observations, where n is the value of variable. If n is not an integer, then SAS truncates it. If n is less than 1 or is missing, then the procedure does not use that observation to calculate statistics.
- The sum of the frequency variable represents the total number of observations.
和
Required Argument
variable
- specifies a numeric variable whose values weight the values of the analysis variables. The values of the variable do not have to be integers. PROC TABULATE responds to weight values in accordance with the following table.
0
: Counts the observation in the total number of observations<0
: Converts the value to zero and counts the observation in the total number of observations.missing
: Excludes the observationTo exclude observations that contain negative and zero weights from the analysis, use EXCLNPWGT. Note that most SAS/STAT procedures, such as PROC GLM, exclude negative and zero weights by default.
Note: Prior to Version 7 of SAS, the procedure did not exclude the observations with missing weights from the count of observations.
Restrictions
- To compute weighted quantiles, use QMETHOD=OS in the PROC statement.
- PROC TABULATE will not compute MODE when a weight variable is active. Instead, try using PROC UNIVARIATE when MODE needs to be computed and a weight variable is active.
Interaction
- If you use the WEIGHT= option in a VAR statement to specify a weight variable, then PROC TABULATE uses this variable instead to weight those VAR statement variables.
Tip
- When you use the WEIGHT statement, consider which value of the VARDEF= option is appropriate. See the discussion of VARDEF=divisor and the calculation of weighted statistics in the Keywords and Formulas section of this document.