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;
Thank you!
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.
How are you computing statistical significance? Where is the information stored?
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.
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.
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:
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;
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
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.
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.
Thank you! This looks like a great way to solve this issue. I will keep this example as a reference.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.