BookmarkSubscribeRSS Feed
ErikT
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');
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?

3 REPLIES 3
pink_poodle
Barite | Level 11
About point 1, Sample 55683 from graph gallery has a broken y-axis. You can adapt it for your x-axis:
https://support.sas.com/sassamples/graphgallery/PROC_SGPLOT.html
About point 2, Sample 48432 has the rotated axis values.
ErikT
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;
   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.

pink_poodle
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'
;
%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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1246 views
  • 0 likes
  • 2 in conversation