René Nyffenegger
René Nyffenegger

Reputation: 40513

How do I order the bars of a bar chart by height rather than alphabetically

Here's a simple data set:

data dat;

  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;

I want to create a bar chart that displays the frequencies of txt:

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

This creates this image

What I'd like instead is to order the bars by height (from left to right: HIJ, ABC, DEFG, KLMN).

Is there an option to proc sgplot to achieve that?

Upvotes: 2

Views: 410

Answers (1)

pinegulf
pinegulf

Reputation: 1396

You can add option categoryorder in your vbar statement:

proc sgplot data = dat;
   vbar txt /categoryorder=respdesc ;
run; quit;

I found it here: http://blogs.sas.com/content/graphicallyspeaking/2012/06/07/bar-chart-with-response-sort/#prettyPhoto enter image description here

Upvotes: 2

Related Questions