The SAS Output Delivery System and reporting techniques

Bar Chart - How to order data groups in each bar?

Reply
N/A
Posts: 0

Bar Chart - How to order data groups in each bar?

I have a bar chart that shows revenue by different segments for each hour in a day. I would like to order each hours revenue data in the bar chart by segment in ascending order. I have pre-sorted the data so that the data is sorted by Time/Date then by Revenue but when I get to PROC GCHART and run the bar chart, each hour is sorted by the Revenue Segment Name, not the Revenue number.

Can I tell it to use the data order (ORDER=DATA) so that my pre-sorted data is preserved in the bar chart?

Thanks,
B
Super Contributor
Super Contributor
Posts: 3,174

Re: Bar Chart - How to order data groups in each bar?

Share your GCHART code please, and ideally some data sample for detail. I know that GCHART stacked-bar "segments" are sorted alphabetically, and so you must use either a SAS PROC FORMAT to map your desired segment order or hardcode the list in your AXIS statement(s), as desired.

Here's a Google advanced search argument which will generate some interesting technical paper, and other DOC references on the SAS support website http://support.sas.com/ for your reference:

+gchart +axis +bar +segment +order site:sas.com


Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Bar Chart - How to order data groups in each bar?

Thanks Scott. See below (FYI - I am using EG and SAS Code to get the desired formatted bar charts).


PROC SORT
DATA=SASUSER.QUERY9255 OUT=WORK.SORTTempTableSorted
;
BY Time_Interval_S DESCENDING CONGESTION_REVENUE
;
RUN;



GOPTIONS CBACK=WHITE xpixels=&_EGCHARTWIDTH pixels=&_EGCHARTHEIGHT;
GOPTIONS COLORS = (.....);

Legend1
FRAME
LABEL=('Congestion Name')

;
Axis1
STYLE=1
WIDTH=1
MINOR=NONE
LABEL=('Congestion Cost' HEIGHT=8pt)
VALUE=(HEIGHT=8pt)

;
Axis2
STYLE=1
WIDTH=1
MAJOR=(Number=12)
LABEL=(HEIGHT=8pt)
VALUE=(HEIGHT=6pt)
MINOR=NONE

;
Axis3

;
Axis3
STYLE=1
WIDTH=1
MAJOR=(Number=12)

PROC GCHART DATA=WORK.SORTTempTableSorted
;
VBAR Time_Interval_S

/
SUMVAR=Congestion_Revenue
SUBGROUP=Congestion_Name
CLIPREF
FRAME DISCRETE

TYPE=SUM
LEGEND=LEGEND1
COUTLINE=BLACK
RAXIS=AXIS1
MAXIS=AXIS2
GAXIS=AXIS3
GAXIS=AXIS3
LREF=1
CREF=BLACK
AUTOREF

;

FORMAT Time_Interval_S DATETIME10.0;
LABEL Time_Interval_S="Date/Time"
;

/* -------------------------------------------------------------------
End of task code.
------------------------------------------------------------------- */
RUN; QUIT;
Super Contributor
Super Contributor
Posts: 3,174

Re: Bar Chart - How to order data groups in each bar?

The GCHART/VBAR parameter SUBGROUP=Congestion_Name controls the bar segment order alphabetically, as mentioned in the DOC. If you want your segments to be ordered otherwise, you will need to build a SAS format, such as a numeric ranking variable, based on CONGESTION_REVENUE, and display the variable value Congestion_Name as the "formatted" variable in your chart. Then apply your formatted value for variable CONGESTION_REVENUE for your SUBGROUP= parameter.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Bar Chart - How to order data groups in each bar?

Thanks Scott, I will give this a try.
Ask a Question
Discussion stats
  • 4 replies
  • 186 views
  • 0 likes
  • 2 in conversation