Data visualization with SAS programming

how to get month names not sorted alphabetically in the graph

Reply
Frequent Contributor
Posts: 117

how to get month names not sorted alphabetically in the graph

Hi all,

I am trying to create a graph with gchart , i need to get Jan-12,Feb-12.....Dec-12 in X-axis ,but i am getting like Apr-12,Aug-12,Feb-12..so on(which is by default giving in ascending order). I want to change this order and i tried with proc gchart NOTSORTED option but it didn't work out. I have month variable which is having values like (january, February,....December) and i have created a format with  labels for month values as

(Jan-12, Feb-12....Dec-12).

sample code;

proc gchart data=chart1;

by notsorted month;

format month $month_name.;

vbar month/sumvar=sales

                midpoints=('01JAN2012'd to '31DEC2012'd)

;

run;

it doesn't yield the result  Please find the attached image for the sample output that i am getting.

Thanks,

Vish

Attachment
Super Contributor
Posts: 1,636

Re: how to get month names not sorted alphabetically in the graph

try:

legend1

        order=('Jan-12' 'Feb-12' ...'Dec-12');

proc gchart data=chart1;

format month $month_name.;

vbar month/sumvar=sales

                midpoints=('01JAN2012'd to '31DEC2012'd)

  legend=legend1;

run;

SAS Employee
Posts: 967

Re: how to get month names not sorted alphabetically in the graph

Once the data is in actual "date" format, you can then use any date format you want

(such as the month name), and the bars will be in proper (date) order, no matter what

the formatted text of the date turns out to be...

data foo;
input bar_date date9. sales;
datalines;
12jan2012 550
12feb2012 600
;


run;

proc gchart data=foo;
format bar_date monname3.;
vbar bar_date / discrete
type=sum sumvar=sales;
run;

SAS Employee
Posts: 967

Re: how to get month names not sorted alphabetically in the graph

When using date values in bar charts, I usually tell it to treat the dates as 'discrete' values.  Otherwise it will want to do grouping/binning of the underlying numeric values that represent the dates.

The following code should get you started:


data foo;

input bar_date date9. sales;

datalines;

12jan2012 550

12feb2012 600

;

run;

proc gchart data=foo;

format bar_date date9.;

vbar bar_date / discrete

type=sum sumvar=sales;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 964 views
  • 1 like
  • 3 in conversation