You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在SAS SGPLOT的VBAR过程中仅显示单个条形?

在SAS SGPLOT的VBAR中仅显示单个条形的方法

可以通过以下两种方式实现,具体取决于你需要的百分比计算逻辑:

场景1:条形百分比基于过滤后的数据(显示为100%)

直接在proc sgplot中添加where语句筛选目标类别,绘图时只会保留该类别的条形:

proc sgplot data=sashelp.birthwgt;
    where married=1; /* 筛选出married=1的观测,仅绘制该条形 */
    vbar married / stat=percent;
run;

场景2:条形百分比基于整个原始数据集

如果需要显示目标类别在总数据中的占比,先计算好对应百分比,再用计算后的数据集绘图:

/* 计算married=1在总数据中的占比 */
proc sql;
    create table married_percent as
    select 
        married,
        count(*) / (select count(*) from sashelp.birthwgt) * 100 as percent
    from sashelp.birthwgt
    where married=1
    group by married;
quit;

/* 基于计算结果绘制单个条形 */
proc sgplot data=married_percent;
    vbar married / response=percent;
run;

内容的提问来源于stack exchange,提问作者pakalla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 01:17:02