sasbar-chartgchart

Tornado diagrams in SAS


There is an example "Tornado Diagram" here. I am trying to modify that code. Here is my modified version:

%let name=ex_17;

goptions reset=(global goptions);
GOPTIONS DEVICE=png xpixels=800 ypixels=600;
goptions gunit=pct border cback=lightgray colors=(blacks) ctext=black
 htitle=6.5 htext=3 ftitle="albany amt" ftext="albany amt";


data mileage;
   input factor $ level $ value;
   datalines;
Screening M 7199
Diagnosis F 4502
Biopsy M 12304
Treatment F 5428
Recovery M 15701
Metastasis F 6915
;

data convert;
   set mileage;
   if level='F' 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, posval.));

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

title1 'One-Way Sensitivity Analysis on NNS to Gain 1 QALY';

*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;

pattern1 value=solid color=green;
pattern2 value=solid color=blue;

proc gchart data=convert;
   format value posval.;
   note move=(25,80) height=3 'Women' move=(+10,+0) 'Men';
   hbar factor / sumvar=value discrete nostat subgroup=level
              maxis=axis1 raxis=axis2 nolegend annotate=anlabels
              coutline=same des='';
run;

quit;

However, as you can see by running this code, the labels for each bar are cut off, not fully visible. Also, some halves of the bars aren't visible.

What am I doing to make these things not visible, and how can I fix this?


Solution

  • Your axis labels are getting cut off in the input dataset.

    data mileage;
       length factor $20;
       input factor $ level $ value;
       datalines;
    Screening M 7199
    Diagnosis F 4502
    Biopsy M 12304
    Treatment F 5428
    Recovery M 15701
    Metastasis F 6915
    ;
    run;
    

    As far as "some halves are not visible", what halves aren't visible? You only have either M or F for each factor, so you aren't going to get two bars on each factor. You're getting all of the bars you're asking for, or at least I see all of them (6 bars, some on left some on right).