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

I am trying to add a significance symbol like an asterisk to the data labels next to my hbars for the values that are significant. My code is below and the graph is shown.

proc sgpanel data=Figure_BarChart_Sex2 noautolegend;
panelby Rate Sex / layout=lattice novarname onepanel ;
hbar Site / group=sex response=AAPC CATEGORYORDER = RESPASC groupdisplay=cluster datalabel DATALABELFITPOLICY=NONE
datalabelattrs=(color=black size=10pt weight=bold) colorresponse=flag2 colormodel=(steelblue firebrick gold);
rowaxis display=(nolabel);
colaxis label="AAPC";
run;

 

fbm_0-1654017642684.png

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I think you need to compute a new variable (probably a text variable) named GORILLA, which is the value of the response variable and it should have an asterisk appended if it is significant. I choose to name it GORILLA as it is unlikely your data set already has a variable by that name.

 

Then in the HBAR statement, use DATALABEL=GORILLA

 

Or use any other name you want, it doesn't really matter.

--
Paige Miller

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

How are you computing statistical significance? Where is the information stored?

--
Paige Miller
fbm
Calcite | Level 5 fbm
Calcite | Level 5

I computed statistical significance already using other software (joinpoint) and I have all the information stored in excel which I import into SAS. This graph is going to be used in a report (word and pdf) so I would like the asterisks to be part of the figure.

PaigeMiller
Diamond | Level 26

I think you need to compute a new variable (probably a text variable) named GORILLA, which is the value of the response variable and it should have an asterisk appended if it is significant. I choose to name it GORILLA as it is unlikely your data set already has a variable by that name.

 

Then in the HBAR statement, use DATALABEL=GORILLA

 

Or use any other name you want, it doesn't really matter.

--
Paige Miller
fbm
Calcite | Level 5 fbm
Calcite | Level 5

Thank you! That worked. I made a new variable in excel that contained the values with an asterisk next to the significant ones and imported that into SAS and used that variable as the data label. Here is my revised code:

proc sgpanel data=Figure_BarChart_Sex2 noautolegend;
panelby Rate Sex / layout=lattice novarname onepanel ;
hbar Site / group=sex response=AAPC CATEGORYORDER = RESPASC groupdisplay=cluster datalabel=gorilla DATALABELFITPOLICY=NONE
datalabelattrs=(color=black size=10pt weight=bold) colorresponse=flag2 colormodel=(steelblue firebrick gold);
rowaxis display=(nolabel);
colaxis label="AAPC";
run;

And the figure:

fbm_0-1654021589732.png

 

 

pink_poodle
Barite | Level 11

It would be easiest to output the graphs in power point then add the asterisks manually:

ods powerpoint file ="path to file/name.pptx";

...your code here...

ods powerpoint close;

sbxkoenk
SAS Super FREQ

See this ( solved ) topic :
Adding a significance star in proc sgplot
https://communities.sas.com/t5/SAS-Programming/Adding-a-significance-star-in-proc-sgplot/td-p/767758

 

Solved by @Ksharp ( who maybe wants to tell sthg. extra since this is PROC SGPANEL ? )

 

Thanks,
Koen

fbm
Calcite | Level 5 fbm
Calcite | Level 5

Thank you. I saw that solution but it only adds an asterisk alone. I want to add an asterisk to the current data label which contains numeric values.

 

ballardw
Super User

If you are not calculating the statistic in the procedure then creating a variable to hold the label might be the easiest.

 

Here is an example with the SASHELP.Class data set.

data myclass;
   set sashelp.class;
   If name in ('Alice' 'John' 'Carol' 'Ronald' ) then significant='*';
   /* the actual datalabel variable*/
   dlabel= cats(put(height,f4.1),significant);
run;

proc sgpanel data=myclass;
   panelby age;
   hbar name /response=height datalabel=dlabel datalabelfitpolicy=none;
run;

I know this doesn't look like your graph but the use of variable to hold a created label should work when the procedure is not using a statistic like Freq or Sum to create data label values. If it were, then pre-summarise the data, add a label variable and the HBARPARM perhaps for the plot if needed.

 

fbm
Calcite | Level 5 fbm
Calcite | Level 5

Thank you! This looks like a great way to solve this issue. I will keep this example as a reference.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 9 replies
  • 1715 views
  • 3 likes
  • 5 in conversation