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');
run;quit;
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 ;
run;
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?
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;
datalines;
A 10
B 15
C 12
D 17
E 205
F 225
;
run;
proc sgplot data=new;
vbar type / response=value;
yaxis ranges=(0-20 200-230);
run;
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
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.
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'
;
%end;
%mend;
%cookie;
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.