How to sort the value in a H-bar graph using proc gchart?

Reply
Occasional Contributor
Posts: 9

How to sort the value in a H-bar graph using proc gchart?

Hi ,

If i am having two variables state and counts in a dataset and i need to produce a h-bar chart using proc gchart.

The values in dataset are

state  counts

ab      5

bc      10

cd       20

unknow 30

uv          40

Total      105

and the values of state and counts are dynamic i.e. it changes monthly.

I need the graph to be displayed with the counts in descending order. Unknow and Total should be last.

The below is the order how the bars should look

uv  40

cd  20

bc  10

ab  5

unknow 30

Total    105

This should be dynamically done ....

Can you guys please help me out with this?

Thanks

Reddi

Super User
Posts: 11,343

Re: How to sort the value in a H-bar graph using proc gchart?

Posted in reply to krishnaboosireddi

The easiest thing I can think of would be to add a dummy variable that would have the value of count for the records except for the unknow and Total which should have negative values so the sort descending works.

dummy = count;

if state='unknow' then dummy= -1;

if state='Total' then dummy = -2;

...

proc  sort ; by dummy descending;

Ask a Question
Discussion stats
  • 1 reply
  • 146 views
  • 0 likes
  • 2 in conversation