Hi,
I've created the graphic in the attachment via Sgplot. However, I also need to add 2 titles at the same level over the graphic. The graphic has a divergent x-axis (of course, the left side is actually negative but formatted as positive for printing). One title should appear on the left side of the 0 base axis-line, the other title on the right side of this 0 base axis-line.
The title statement only offers left, right and center, the "left option" sends the "title ABC" way far to the left, the "center option" overlaps the "title XYZ". The title XYZ luckily locates well with the option "right".
Sugestions on how to precisely locate the 2 titles in the same line in this case? Thanks for your time.
Regards,
Karl
There are a few ways to of this, but this way is probably the most straightforward. The key here is the annotation, and the PAD option on the procedure. Let me know if you have any questions.
Thanks!
Dan
data test;
input x y;
cards;
-60 0
60 100
;
run;
data anno;
retain function "text" y1 100 drawspace "wallpercent" width 40
anchor "bottom" textstyleelement "GraphTitleText";
input x1 label $ 4-12;
cards;
25 Title ABC
75 Title XYZ
;
run;
proc sgplot data=test sganno=anno pad=(top=30);
scatter x=x y=y;
refline 0 / axis=x;
run;
p.s. I don't see my atachment...trying again.
The graph didn't get attached.
There are a few ways to of this, but this way is probably the most straightforward. The key here is the annotation, and the PAD option on the procedure. Let me know if you have any questions.
Thanks!
Dan
data test;
input x y;
cards;
-60 0
60 100
;
run;
data anno;
retain function "text" y1 100 drawspace "wallpercent" width 40
anchor "bottom" textstyleelement "GraphTitleText";
input x1 label $ 4-12;
cards;
25 Title ABC
75 Title XYZ
;
run;
proc sgplot data=test sganno=anno pad=(top=30);
scatter x=x y=y;
refline 0 / axis=x;
run;
Thank you Dan,
an elegant solution, btw, after this I found your paper about annotating graphs, all very useful.
Regards,
Karl
@Karolus wrote:
The title statement only offers left, right and center, the "left option" sends the "title ABC" way far to the left, the "center option" overlaps the "title XYZ". The title XYZ luckily locates well with the option "right".
You can "pad" text so it appears that things are not all the way to the left
title justify=left " Some left text" justify=right "And some right text "; proc print data=sashelp.class (obs=5); run;
The "spaces" in the text are actually null, ASCII 255 characters and don't get stripped out the way a simple space might. More of a "something that may work occasionally" then an always do this.
/*
You could pad some blanks in TITLE
*/
title 'XXXXX YYYYY';
proc sgplot data=sashelp.heart;
hbar bp_status/response=weight group=sex;
run;
Using spaces is an option, particularly is this is a "one-off" graph. However, if this is something you will re-use, possible at different sizes and with different output types, you'll want to use an approach that guarantees that the text will be anchored in the correct location.
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 25. 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.