sas - 在SAS中绘制直方图和箱线图

标签 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 ......................................

我对箱线图也有同样的问题,例如我得到了下面的图,我想更改距离,然后我可以更好地看到图,但我看不到。

enter image description here

最佳答案

下面是针对 proc univariate 而不是 proccapability,我无权访问 SAS/QC 进行测试,但用户指南显示了非常相似的语法直方图陈述。希望您能够将其翻译回来。

由于输出系统的原因,您似乎遇到了颜色问题。您的图形可能是通过 ODS 提供的,在这种情况下,cfill 选项不适用(请参见 here 而不是传统图形标签)。

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

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 将限制仅在比较直方图中显示的 bin 数量。

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

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;

关于sas - 在SAS中绘制直方图和箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25952298/

相关文章:

arrays - 在 SAS 中生成数组的所有唯一排列

SQL - 如何将查询结果的计数添加到表中

r - 使用小时更改 bin 大小 :Minute In ggplot histogram

sas - 根据 SAS 中的第一次观察标记 ID

histogram - PCL 点特征直方图 - 分箱

python - 在同一张图上绘制两个直方图,并使它们的列总和为 100

matlab - 当我应用 notboxplot 函数生成 beeswarm 箱线图时,如何更改标记透明度?

python - 箱线图按 python pandas 中的列分层

r - ggplot2 在箱线图顶部添加文本

error-handling - SAS : How to Prevent ABORT on Error