Search notes:

SAS - proc sgplot: bar charts

Sort by response value

By default, the bars are ordered alphabetically.
With categoryorder=respdesc, the bars are ordered by their height (response value).
data dat;

  length txt $10;

  do i = 1 to 100;

     if      rand('unif') > 0.85 then txt = 'DEFG';
     else if rand('unif') > 0.75 then txt = 'ABC';
     else if rand('unif') > 0.80 then txt = 'KLMNOP';
     else                             txt = 'HIJ';

     output;
  end;

run;

ods graphics on;

proc sgplot data = dat;
/* Bars are ordered alphabetically by default: */
   vbar txt;
run;

proc sgplot data = dat;
   vbar txt /
        /* respdesc: Order the response values
                     in descending order. */ 
        categoryorder=respdesc ;
run;
Github repository about-SAS, path: /programming/proc/sgplot/bar/order-by-response-value.sas

Restrict drawn bars

The following example uses
xaxis type=discrete values=('one' 'two' 'three' 'four' 'five' 'six' 'seven' 'eight' 'nine' 'ten');
to choose which bars should be drawn:
ods graphics on;


data tq84_distribution;

  call streaminit(2808);

  do obs = 1 to 1000; /* Create 1000 observations */
 
     num = 1;
     do while(1);
        if rand('norm') > 1 then leave;
        num = num+1;
     end;
     
     txt = put(num, words30.);
     
     output;
     
  end;

run;

proc sgplot data = tq84_distribution;
   vbar txt;
        
   xaxis type=discrete values=('one' 'two' 'three' 'four' 'five' 'six' 'seven' 'eight' 'nine' 'ten');

run;
Github repository about-SAS, path: /programming/proc/sgplot/bar/xaxis/select-values.sas

See also

proc sgplot
Data visualization: Bar charts

Index