我正在尝试使用SAS制作条形图。我有多个工资数据,我想显示这些工资频率的条形图。我做了这个:
ODS GRAPHICS ON;
PROC FREQ DATA=WORKERS.SORT ORDER=INTERNAL;
TABLES salaries / NOCUM SCORES=TABLE plots(only)=freq;
RUN;
ODS GRAPHICS OFF;
它有效,问题是,现在我可以在x轴上看到所有(数百个)工资。我希望只有这些工资的间隔(如20),这样我就可以获得更易读的图表。我无法找到如何做到这一点。我也尝试过这个:
PROC CHART DATA=WORK.SORT;
vbar salaries;
RUN;
但这是图表的文字表示,所以我无法使用它。
答案 0 :(得分:2)
您可以创建格式并将格式应用于要分组到存储桶中的变量。这是一个例子:
proc format ;
value myfmt
low - 13 = '13 and Under'
14 - high = '14 and Above';
run;
ODS GRAPHICS ON;
PROC FREQ DATA=sashelp.class ORDER=INTERNAL;
format age myfmt.;
TABLES age / NOCUM SCORES=TABLE plots(only)=freq;
RUN;
ODS GRAPHICS OFF;
答案 1 :(得分:2)
将PROC UNIVARIATE与HISTOGRAM语句一起使用。 http://support.sas.com/documentation/cdl/en/procstat/66703/HTML/default/viewer.htm#procstat_univariate_toc.htm
ods html;
proc univariate data=sashelp.cars noprint;
var msrp;
histogram;
run;
可以选择指定箱尺寸:
ods html;
proc univariate data=sashelp.cars noprint;
var msrp;
histogram / midpoints=30000 to 180000 by 30000;
run;
答案 2 :(得分:0)
为了完整起见,我会添加另一种解决方案,以防您想要更好地控制图表的外观。使用图形模板语言,您可以创建一些非常漂亮的图表。
proc template
语句定义了图表的外观。 sgrender
针对指定的数据集运行图表。在线文档中最好地探讨了各种选项:http://support.sas.com/documentation/cdl/en/grstatgraph/65377/HTML/default/viewer.htm#p1sxw5gidyzrygn1ibkzfmc5c93m.htm
我刚刚提供了他们提供的示例,并添加了/ nbins=20
选项,让它自动分组到20个分箱中。它还有开始和结束箱,箱尺寸等选项。
proc template;
define statgraph histogram;
begingraph;
entrytitle "Histogram of Vehicle Weights";
layout overlay /
xaxisopts=(label="Vehicle Weight (LBS)")
yaxisopts=(griddisplay=on);
histogram weight / nbins=20;
endlayout;
endgraph;
end;
run;
proc sgrender data=sashelp.cars template=histogram;
run;