我使用PROC FORMAT
如下方法在数据中创建了缺失值:
proc format;
value ideofmt
1-2='Lib or Extr Lib'
3-5='Mod, Slight Lib or Slight Cons'
6-7='Cons or Extr Cons'
other=.;
run;
当我尝试使用进行拟合优度检验时PROC FREQ
,它决定包括other
我编码为missing(.
)的值。这是我的代码:
proc freq data=sasuser.project2;
table ideology /nocum chisq testp = (0.2 0.6 0.2);
format ideology ideofmt.;
run;
我反复收到以下错误:
ERROR: The number of TESTP values does not equal the number of levels. For the table of
ideology, there are 4 levels and 3 TESTP values.
此错误(以及频率表输出)表明,PROC FREQ
仍然认为我的缺失值可用于计算(即,我有4个值,而不是3个值)。
我的假设是PROC FREQ
默认情况下排除缺失值,因此我不确定代码有什么问题。
任何帮助将不胜感激。
这是SAS所做的与您预期的有所不同的示例。
如果存在真正的缺失,SAS将把缺失格式的值折叠为缺失。这不是因为您格式化它们的方式.
-它将折叠任何东西,使其丢失,即使您的值不是丢失的值,也可以将其格式化为与丢失相同的结果。如果不存在任何缺少基础(未格式化)值的值,则将显示该值。
请参见以下示例。查看将“其他”更改为“”时发生的情况。或者什么都没有!
proc format;
value milef
10-<15 = "Low"
15-<25 = "Medium"
25-40 = "High"
other = "Something Else";
quit;
proc freq data=sashelp.cars;
tables mpg_highway;
format mpg_highway milef.;
run;
data cars;
set sashelp.cars;
if mpg_highway = 66 then mpg_highway=.;
run;
proc freq data=cars;
tables mpg_highway;
format mpg_highway milef.;
run;
为了使示例生效,您需要在数据中引入单个true缺失,或者以其他方式进行处理(使用WHERE子句过滤掉所有不适用的方法是最简单的)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句