SAS proc GCHART HBAR语句中显示的数据顺序

时间:2013-04-28 19:44:05

标签: sas bar-chart gchart

我有以下内容,但我希望控制数据的显示顺序。我不希望按照A,B,C,D,E,F的顺序显示条形,而是希望根据用户指定的顺序显示条形。例如,我希望能够在SAS数据集中为一个名为rank的变量赋值,该变量将控制条形图的堆叠顺序。

我该怎么做?

%let name=ex_17;
%let myfont=Albany AMT;
goptions reset=all;
goptions reset=(global goptions);
/*GOPTIONS DEVICE=png xpixels=800 ypixels=400;*/
goptions gunit=pct border cback=white colors=(blacks) ctext=black
htitle=4 htext=3.0 ftitle="&myfont" ftext="&myfont";

data mileage;
      length factor $ 24;
   input factor $ level $ value;    
   datalines;
C left -38.882
C right 39.068
D right 38.99
D left -38.97
E right 38.982
E left -38.975
F left -38.973
F right 38.979
B left -38.975
B right 38.975
A right 38.977 
A left -38.973
;

/* base case: 38.975  */
data mileage;
    set mileage;
    if level="right" then value = value - 38.975;
    if level="left" then value = -1*(38.975 - value*-1);
run;

data convert;
   set mileage;
   *if level='left' then value=-value;
run;

proc format;
   picture posval low-high='000,009';
run;

data anlabels(drop=factor level value);
   length text $ 24;
   retain function 'label' when 'a' xsys ysys '2' hsys '3' size 2;

   set convert;
   midpoint=factor; subgroup=level;

   *text=left(put(value, BEST6.3));

   if level ='left' then position='>';
   else position='<'; output;
run;

title1 'Sensitivity Analysis graph';
*footnote1 justify=left ' SAS/GRAPH' move=(+0,+.5) 'a9'x move=(+0,-.5) ' Software'
          justify=right 'DRIVER ';
*title2 'by Daniel Underwood' h=3.0;
footnote1 'Estimates accurate within +/- 0.002';

*axis1 label=(justify=left 'Disutility') style=0 color=black;
axis1 label=(justify=left '') style=0 color=black;
*axis2 label=none value=(tick=3 '') minor=none major=none
      width=3 order=(-10000 to 20000 by 10000) color=black;
axis2 label=none minor=none major=none value=(tick=3 '')
      width=3 order=(-0.093 to 0.093 by 0.186) color=black;


pattern1 value=solid color=ltgray;
pattern2 value=solid color=ltgray;
/*
goption vpos=25;
goptions vsize=5in;
*/
proc gchart data=convert;
   format value BEST6.3;
   note move=(40,90) height=3 'Women' move=(+12,+0) 'Men';
   hbar factor / sumvar=value discrete nostat subgroup=level
              maxis=axis1 raxis=axis2 nolegend annotate=anlabels
              coutline=same des='' space=2;
run;

quit;

1 个答案:

答案 0 :(得分:1)

显示的值的顺序由AXIS语句(订购中点或图表变量)或LEGEND语句(订购子组变量的值)上的ORDER =选项控制。

如果您想要一种方法来使用名为RANK的变量来控制子组变量的顺序,here is a SAS sample program就是这样做的。