Proc Freq表示不存在的值。

时间:2016-03-27 19:44:26

标签: sas

我有一个包含Color列的数据集。我在这一栏中有黑白红的价值观。当我试图计算表格列的频率时,我得到黑色,白色和红色的结果。但我还需要显示绿色和蓝色的零频率。如果我在Color Color列中没有这两种颜色,我怎么能这样做呢?

2 个答案:

答案 0 :(得分:1)

最简单的方法是使用PROC MEANS,如下所示:

proc format;
  value colors 1 = "Black"
               2 = "White"
               3 = "Red"
               4 = "Green"
               5 = "Blue";
run;

data mytable;
  input color;
  format color colors.;
  datalines;
1
2
1
3
;

proc means data=myTable completetypes;
   class color / preloadfmt;
run;

Results from proc means

另一种方法是使用PROC TABULATE,指定包含所有可能值的附加输入表(classdata参数),如下所示:

data allColors;
  input color;
  format color colors.;
  datalines;
1
2
3
4
5
;

proc tabulate data=mytable classdata = allColors;
  class color;
  table color / misstext = "0";
run;

结果:

Proc Tabulate Results

答案 1 :(得分:-1)

使用缺少选项:

MISSING
treats missing values as a valid nonmissing level for all TABLES variables. 
Displays missing levels in frequency and crosstabulation tables and includes 
them in computations of percentages and statistics.

另见:http://support.sas.com/documentation/cdl/en/procstat/63104/HTML/default/viewer.htm#procstat_freq_sect016.htm