在SAS中绘制直方图和箱形图

时间:2014-09-20 04:09:20

标签: sas histogram boxplot

我在sas中编写了以下代码,但是我没有得到结果!

灰色的结果直方图和数据范围不是我指定的!有什么问题?

我也收到了以下警告:警告:扩展了MIDPOINTS =列表以容纳数据

颜色怎么样?

axis1 order=(0 to 100000 by 50000);
axis2 order=(0 to 100 by 5);
run;
proc capability data=HW2 noprint;
histogram Mvisits/midpoints=0 to 98000 by 10000
haxis=axis1
cfill=blue;
run;

enter image description here .......................................

我对boxplot有同样的问题,例如我得到了以下情节,我想改变距离,然后我可以看到情节更好,但我不能。

enter image description here

1 个答案:

答案 0 :(得分:3)

以下内容适用于proc univariate而不是proc capability,我无法访问SAS / QC进行测试,但是用户指南显示了直方图语句非常相似的语法。希望您能够将其翻译回来。

由于您的输出系统,您的颜色看起来很糟糕。您的图表可能是通过ODS提供的,在这种情况下,cfill选项不适用(请参阅here而不是传统图形标记)。

要更改ODS输出中直方图条的颜色,您可以使用proc template

proc template;
    define style styles.testStyle;
        parent = styles.htmlblue;
        style GraphDataDefault /
            color = green;
    end;
run;

ods listing style = styles.testStyle;

proc univariate data = sashelp.cars;
    histogram mpg_city;
run;

可以找到解释此问题的示例here

或者,您可以使用proc sgplot创建一个更多颜色控制的直方图,如下所示:

proc sgplot data = sashelp.cars;
    histogram  mpg_city / fillattrs = (color = red); 
run;

关于截断直方图的问题。忽略极端值并没有多大意义,因为它会给你一个错误的分布图像,这有点违背了直方图的目的。也就是说,你可以通过一些黑客来实现你所要求的:

data tempData;
    set sashelp.cars;
    tempClass = 1;
run;

proc univariate data = tempData noprint;
    class tempClass;
    histogram mpg_city / maxnbin = 5 endpoints = 0 to 25 by 5;
run;

在上面创建了一个虚拟类tempClass,然后使用class语句请求比较直方图。 maxnbins将限制仅在比较直方图中显示的区域数。

您的另一个选择是在创建直方图之前排除(或限制)您的极值点,但这会导致略微错误的频率计数/百分比/条形高度。

data tempData;
    set sashelp.cars;
    mpg_city = min(mpg_city, 20);
run;

proc univariate data = tempData noprint;
    histogram mpg_city / endpoints = 0 to 25 by 5;
run;

这是原始问题的可能方法(未经测试,没有SAS / QC或数据):

proc capability data = HW2 noprint;
    histogram Mvisits / 
        midpoints = 0 to 300000 by 10000
        noplot 
        outhistogram = histData;
run;
proc sgplot data = histData;
    vbar _MIDPT_ / 
        response = _OBSPCT_ 
        fillattrs = (color = blue);
    where _MIDPT_ <= 100000;
run;