我使用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值。这是我的密码:
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排除了缺失的值,所以我不确定我的代码有什么问题。
任何帮助都将不胜感激。
发布于 2014-10-30 15:14:36
这是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;为了使示例有效,您需要在数据中引入一个缺失的真,或者以不同的方式处理它(使用WHERE子句筛选出不适用的任何最简单的内容)。
https://stackoverflow.com/questions/26641852
复制相似问题