BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Juen
Fluorite | Level 6

Hi SAS experts,

I try to use annotation to place a label in between two bars. But I can only put it on top of one bar, and don't know how to put it in between two bars.

In the below code, I try to place the label "p=0.001" in between bars "RC and "RF".  In another word, I try to put the label on top-middle of the the line generated by the code

function=  "polycont"; xc1="RC"; y1=49;  output;

function=  "polycont"; xc1="RF"; y1=49;  output;

I have tried to give a large value of width, it didn't work either. It always sits on top of the "RC" bar.

Can anybody help me?

I am using SAS 9.3 M1.

Thanks a lot!

Juen

Here is my code:

data bites_results;   * bites per 100 kcal;

input meal $ 1-31 diet $ 32-37 size bites bites_SE;

datalines;

                     B         RC        34      33.2941176       2.0170969

                     B         RF        23      43.2173913       2.5683976

                     B         EB        46      46.9565217       2.1526204

;

run;

data bites_results; set bites_results;

meal= compress(meal);

upper=bites + bites_SE;

lower=bites - bites_SE;

run;

data anno;

length xc1 $2;

retain drawspace "datavalue" linethickness 4;

function = "polyline"; xc1="RC"; y1= 37; output;

function=  "polycont"; xc1="RC"; y1=49;  output;

function=  "polycont"; xc1="RF"; y1=49;  output;

function=  "polycont"; xc1="RF"; y1=47;  output;

function=  "text";     xc1="RC"; y1=50; label= "p=0.001"; textsize=15;  width=100; output;

run;

proc sgplot data=bites_results sganno=anno;

vbarparm category=diet response= bites /limitupper = upper limitlower=lower LIMITATTRS=(thickness=2) ;

yaxis label="Bite Count" labelattrs=(size=20) valueattrs=(size=20) offsetmin = 0;

xaxis display=(nolabel) valueattrs=(size=20) ;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

To place anything on a discrete axis in a place other than the midpoint value, use the DISCRETEOFFSET attribute.  To put something halfway between A and B (adjacent values), use XC1='A' and DiscreteOffset=0.5  OR XC1='B' and DiscreteOffset= -0.5.

View solution in original post

3 REPLIES 3
Jay54
Meteorite | Level 14

To place anything on a discrete axis in a place other than the midpoint value, use the DISCRETEOFFSET attribute.  To put something halfway between A and B (adjacent values), use XC1='A' and DiscreteOffset=0.5  OR XC1='B' and DiscreteOffset= -0.5.

Juen
Fluorite | Level 6

Thanks. It does the trick.

Below is my code just in case others may be interested.

function=  "text"; xc1="RC"; DiscreteOffset=0.5; y1=50; label= "p=0.001"; textsize=15;  width=100; output;

Thanks a lot.

Juen

Jay54
Meteorite | Level 14

FYI...It is also possible to place text in the graph using the MARKERCHAR option of the SCATTER plot.  The data can come from the procedure data set and you can use DiscreteOffset the same way.  With SAS 9.4M2, you can also use the TEXT statement.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 897 views
  • 3 likes
  • 2 in conversation