BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
Thanks Scott, I will give this a try.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 788 views
  • 0 likes
  • 2 in conversation