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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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