BookmarkSubscribeRSS Feed
Obsidian | Level 7

Attached file is a VBAR created with good old PROC GCHART. It depicts response times to requests in days. The first 4 weeks on a daily basis and beyond that on a weekly basis. Note the clear gap at the junction between the daily and weekly bars.

The PROC GCHART coding is:

proc gchart data=selection annotate=anno;
vbar workdays/midpoints=0 to 28 by 1 28 to 308 by 7 raxis=axis1 maxis=axis2;
axis1 order=0 to 130 by 10 label=(a=90 'Aantal gevallen');
axis2 label=('Doorlooptijd in werkdagen');

The reference lines and text are added with the Annotate facility.

I tried to reconstruct this chart with PROC SGPLOT. I used following code for it (I did not yet include the annotates):

proc sgplot data=selection;
vbar days/fillattrs = (color=cyan);
xaxis values=(0 to 28 by 1 28 to 308 by 7) ranges=(1-28 28-308) valuesrotate=vertical ;
STYLEATTRS axisbreak=bracket ;

I ran into two problems with this:

1. The midpoint axis contained the values as given in the Xaxis statement, but the graph did not show the gap between the two range definitions

2. I wanted the tick-marks formatted as in GCHART (so stacked digits), but I was only able to rotate the labels.

Has anybody suggestions how to proceed?

Barite | Level 11
About point 1, Sample 55683 from graph gallery has a broken y-axis. You can adapt it for your x-axis:
About point 2, Sample 48432 has the rotated axis values.
Obsidian | Level 7

Thank you for the suggestions. It learned me something new at one point. If you define ranges they should include some gap: This is the code of sample 55683:

data new;
   input Type $1 Value;
A 10
B 15
C 12
D 17
E 205
F 225

proc sgplot data=new;
   vbar type / response=value;
   yaxis ranges=(0-20 200-230);

Changing the range definition to adjacent ranges [yaxis ranges=(0-20 20-230);] makes the break disappear. But even a minimal gap is sufficient: [yaxis ranges=(0-20 20.01-230);] to see it again.

What the example does not do is use a different scale for the two halves of the axis as GCHART does. 

Sample 48432 rotates the values, but that is not what I want. I want them stacked as in the GCHART output. So:

1  1  1

    0  0

So the questions are still open and a challenge for all readers.

In the mean time I will look into SGPANEL to see whether I can solve my first question with that procedure or I will dig into PROC TEMPLATE to try to define it myself.

Barite | Level 11

You would need a split-character format. There is some repetition, so try using a macro like this:
%macro cookie; *makes a split-character format;
proc format;
value $split
%do i = 10 %to 230 %by 10;
i = break into characters and fuse using ~ symbol, so 10 becomes '1~0';
last bit of value statement would be
230 = '2~3~0'


axis2 split = "~";
xaxis = axis2;
format value $split;

This is based on Solution # 3 from "Charting the Basics with PROC GCHART" by Perry Watts. It will apply to sgplot, because axis statement is outside of procedure.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2 in conversation