BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Karolus
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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;

View solution in original post

8 REPLIES 8
Karolus
Obsidian | Level 7

p.s.  I don't see my atachment...trying again.

DanH_sas
SAS Super FREQ

The graph didn't get attached.

Karolus
Obsidian | Level 7
yeah, I noticed, I just added it
DanH_sas
SAS Super FREQ

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;
Karolus
Obsidian | Level 7

Thank you Dan,

an elegant solution, btw, after this I found your paper about annotating graphs, all very useful.

 

Regards,

Karl

ballardw
Super User

@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.

 

Ksharp
Super User
/*
You could pad some blanks in TITLE
*/

title 'XXXXX                                                 YYYYY';
proc sgplot data=sashelp.heart;
hbar bp_status/response=weight group=sex;
run;

Ksharp_0-1693484132653.png

 

DanH_sas
SAS Super FREQ

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. 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1112 views
  • 2 likes
  • 4 in conversation