I'm trying to create a horizontal barchart with a label above the y-axis values (left aligned) and also a label above the bars (left aligned).
In a simple GTL barchart I can get the "unit" label but couldn't get the "Some measurement" label above the bars (only at the bottom of the bars) so i figured I'd try and put the y-axis values and the "unit" label in an axistable. So I created a layout lattice with two layout overlays in it, one for the axistable (showing values and label) and one for the barchart (showing only the label). However as seen above the two labels won't align. The label for the axistable is higher than the label for the barchart.
So my question is:
Is it possible to get the x-axis label on top of the bars aligned with the y-axis label (and skip the axistable) or
keep the axistable and somehow align not only the axistable/barchart values but also the labels?
The template needs to accomodate diffrent number of bars (and thereby different graph heights) so using drawtext isn't really an option (as far as I can see)..
A quick and dirty try might be to add a referenceline with datatransparency set to completely transparent (doesn't show) and use the curvelabel options to control appearance and location. You would need to provide an axis value for the transparent line.
The labels should line up vertically. I suggest you report it to SAS Tech Support as a defect.
Aside from that, you could creatively use the BARCHART with TEXTPLOT statement to do this. The data will include an extra text column with the value "Some measurement" for an additional category value of "Unit". The data set has to be judiciously created or merged. You could likely also do this using SGPLOT with VBARPARM and TEXT. I will try it to see if this works using dummy data.
Since @DanH_sas provided a good solution, I will skip further work on this.
Here is a little example that demonstrates one way to do it:
ods graphics / width=640px height=200px;
data test;
length cat $ 9;
input cat $ resp;
cards;
category1 50
category2 30
category3 70
;
run;
data label;
function="text";
drawspace="wallpercent";
x1=0;
y1=100;
anchor="bottomleft";
label="Some Measurement";
width=40;
output;
run;
proc sgplot data=test sganno=label;
yaxis display=none;
xaxis display=(nolabel);
hbarparm category=cat response=resp;
yaxistable cat / position=left labeljustify=left;
run;
Hope this helps!
Dan
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: