BookmarkSubscribeRSS Feed
Vish33
Lapis Lazuli | Level 10

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


SampleOutput.JPG
3 REPLIES 3
Linlin
Lapis Lazuli | Level 10

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;

GraphGuy
Meteorite | Level 14

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;

GraphGuy
Meteorite | Level 14

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;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3454 views
  • 1 like
  • 3 in conversation