更改sas图上的条形顺序

时间:2017-02-15 10:44:25

标签: sas sas-macro

我有一个宏,可以生成图像graph中的图形。我想将条形顺序更改为Dev 201601 201602 201603 201604 201605而不是。{ 201601 201602 201603 201604 201605 Dev。这是我的代码

goptions reset=global gunit=pct border cback=white 
colors=(black red green blue) ftitle=swissb
ftext=ZAPFB htitle=5 htext=1.7
offshadow=(1.5,1.5);
axis1 label=none;
axis2 label=none value=none
order=(0 to 110 by 10)
major=none
minor=none;
legend1 cborder=black cblock=CXF0E68C label=none
shape=bar(3,3)
POSITION=(bottom center);
pattern1 color=vpapb;
pattern2 color=bigy;
pattern3 color=paoy;
pattern4 color=vligb;
pattern5 color=lipk;
pattern6 color=vpap;
pattern7 color=pab;
pattern8 color=lio;

proc gchart data= Recent.char_&value;
title ;
vbar Period / sumvar=Percent
subgroup=&value
inside=subpct
width=12
space=8
maxis=axis1
raxis=axis2
legend=legend1
cframe=BWH
coutline=black;

我该怎么做才能解决问题?

1 个答案:

答案 0 :(得分:0)

最简单的方法是将条形值设为一个排序值,使用格式显示为实际值。所以这里我有0 = Dev,1 = 201601,2 = 201602等;我使用图片格式来实现目标,因为事情很好,但如果没有像这样的简单逻辑映射,你可以使用常规值格式。

data test_data;
input period value; /* you may need to convert from '201601' to '1' if your data already has 201601 type values;  use an informat (opposite of format). */
datalines;
1 10
2 20
3 25
4 25
5 30
0 20
;;;;
run;

proc format;
picture periodF
0 = 'Dev'  /* map 0 to Dev */
1-12 = 99 (prefix='2016');  /* for values 1-12, display in 2 digit zero padded format, prefix with 2016) */
quit;

proc sgplot data=test_data;
  format period periodf.;    /*apply format here or in an earlier datastep */
  vbar period/response=value;
run;