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

First, sorry for the redundancy: I found a post written by @js5 that corresponds to my problem (proc sgpanel: is datalabel supposed to work with limitlower and limitupper?) but it is closed with no clear answer to the original question (Is DATALABEL supposed to work with LIMITLOWER and LIMITUPPER in PROC SGPANEL?) and the proposed solution does not work for me so here we go with a new post on the matter:

 

I have a simple dataset structured as follows:

data my_data_SGPANEL;
input food_group  sex  select_var  Mean  LowerCLMean  UpperCLMean;
datalines;
111  1  0  6.2  5.6  6.8
111  1  1  2.7  2.1  3.3
111  2  0  4.9  4.5  5.4
111  2  1  1.5  1.0  2.0
112  1  0  2.3  2.0  2.6
112  1  1  0.9  0.6  1.1
112  2  0  2.9  2.5  3.3
112  2  1  2.4  1.3  3.4
...
; 
run; 

I have attached the complete dataset to my post. I am on SAS 9.4M5.

 

I would like to use a SGPANEL procedure to plot bar charts by sex side by side. I have tried using PROC SGPANEL with options DATALABEL, LIMITLOWER and LIMITUPPER to get error bars and value labels displayed on the graphs. I used option DATALABEL without a variable, as specified in SAS Documentation (here for the LIMITLOWER option). However, it looks like options DATALABEL and LIMITLOWER/LIMITUPPER are simply incompatible. When I use them together, I get this note in my LOG, twice (one for LIMITLOWER and the other for LIMITUPPER, I guess):

NOTE: La barre d'erreur ne prend en charge l'option DATALABEL=. Le libellé ne sera pas ajouté.

Which roughly translates to “The DATALABEL= option is not supported by the error bar. The label will not be added.” (Sorry for the poor translation but the original first French sentence is pretty bad and actually does not mean anything… Like in @js5's post, not sure where French is coming from here since all the other messages in my LOG are in English).


Here is the code:

/* Formats used in the graphs */
proc format; 
	/** Yes / No **/
	value ynfmt 0 = "No"  1 = "Yes";
	/** Food groups **/
	value fdgpfmt 111 = "red meat" 112 = "poultry" 113 = "game" 114 = "offals" 115 = "processed meat";
run; 

/* SGPANEL procedure */
proc sgpanel data = my_data_SGPANEL;
	panelby sex;
	vbarparm category = food_group response = Mean / group = select_var  groupdisplay = cluster  DataLabel  LimitLower = LowerCLMean  LimitUpper = UpperCLMean  LimitAttrs = (Color = black);
	format sex sexfmt.  food_group fdgpfmt.  select_var ynfmt.  Mean F4.1  LowerCLMean F4.1  UpperCLMean F4.1; 
	ColAxis display = (NoLabel); 
	RowAxis label = "Percents";
run; 

And here is the output (error bars but no data labels):

SGPanel110.png

 

If I remove options LIMITLOWER, LIMITUPPER and LIMITATTRS from the code above, the data labels are displayed on top of the bars (and I could not find how to choose their position on the graph) but, as expected, no limit lines are displayed:

SGPanel112.png


I guess that one solution could be to use a SGPLOT procedure by sex: 

proc sort data = my_data_SGPANEL; by sex; run; 
proc sgplot data = my_data_SGPANEL;
	by sex;
	vbarparm category = food_group response = Mean / group = select_var  GroupDisplay = cluster  DataLabel  LimitLower = LowerCLMean  LimitUpper = UpperCLMean  LimitAttrs = (Color = black);
	format sex sexfmt.  food_group fdgpfmt.  select_var ynfmt.  Mean F4.1  LowerCLMean F4.1  UpperCLMean F4.1; 
	xAxis display = (NoLabel); 
	yAxis label = "Percents";
run; 

 

Using PROC SGPLOT, the output for sex = Male:

SGPlot1258.png

 

Using the graphs generated by the SGPLOT procedure, I could "create" the panel through post-editing. However, it would be better if I could get SAS to do this panel directly to avoid going through post-editing. So Is DATALABEL supposed to work with LIMITLOWER and LIMITUPPER when using PROC SGPANEL? If so, how should I proceed? Any suggestions? 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @Mombi,

 

I think you can add the desired table by using the COLAXISTABLE statement:

 

proc sgpanel data = my_data_SGPANEL;
  panelby sex;
  vbarparm category = food_group response = Mean / group = select_var  groupdisplay = cluster  DataLabel  LimitLower = LowerCLMean  LimitUpper = UpperCLMean  LimitAttrs = (Color = black);
  format sex sexfmt.  food_group fdgpfmt.  select_var ynfmt.  Mean F4.1  LowerCLMean F4.1  UpperCLMean F4.1; 
  ColAxis display = (NoLabel); 
  RowAxis label = "Percents";
  colaxistable LowerCLMean Mean UpperCLMean / class=select_var classdisplay=cluster;
run; 

At least this works on my SAS 9.4M5 (where I do not get notes in the log about incompatibility of DATALABEL and error bars).

SGPANEL_COLAXISTABLE.png

 


@Mombi wrote:

 

NOTE: La barre d'erreur ne prend en charge l'option DATALABEL=. Le libellé ne sera pas ajouté.

(...) not sure where French is coming from here since all the other messages in my LOG are in English

You can obtain those special log messages in English by (temporarily) changing the value of the LOCALE system option:

options locale=EN_US;

 

View solution in original post

4 REPLIES 4
Ksharp
Super User

For your this sepcial case ,you could use SCATTER statement to mimic DATALABEL as you wished.

 

libname x 'C:\Users\xiakeshan\Documents\Downloads';
data my_data_SGPANEL;
 set x.my_data_SGPANEL;
run;




/* Formats used in the graphs */
proc format; 
	/** Yes / No **/
	value ynfmt 0 = "No"  1 = "Yes";
	/** Food groups **/
	value fdgpfmt 111 = "red meat" 112 = "poultry" 113 = "game" 114 = "offals" 115 = "processed meat";
run; 

/* SGPANEL procedure */
proc sgpanel data = my_data_SGPANEL;
	panelby sex;
	vbarparm category = food_group response = Mean / group = select_var  groupdisplay = cluster   LimitLower = LowerCLMean  LimitUpper = UpperCLMean  LimitAttrs = (Color = black);

	scatter x=food_group y=mean/group = select_var  groupdisplay = cluster datalabel datalabelpos=right datalabelattrs=(color=black) markerattrs=(size=0);
    scatter x=food_group y=LowerCLMean/group = select_var  groupdisplay = cluster datalabel datalabelpos=right datalabelattrs=(color=black) markerattrs=(size=0);
	scatter x=food_group y=UpperCLMean/group = select_var  groupdisplay = cluster datalabel datalabelpos=right datalabelattrs=(color=black) markerattrs=(size=0);

	format   food_group fdgpfmt.  select_var ynfmt.  Mean F4.1  LowerCLMean F4.1  UpperCLMean F4.1; 
	ColAxis display = (NoLabel); 
	RowAxis label = "Percents";
run; 

Ksharp_0-1746165227859.png

 

Mombi
Fluorite | Level 6

Thank you for taking the time to help me, @Ksharp 🙂

Indeed, I thought about using SCATTER statements to add the labels but the output is a bit messy, even if I use different positions with option DATALABPOS to space the labels apart and avoid overlapping : 

proc sgpanel data = my_data_SGPANEL;
	PanelBy sex;
	vbarparm category = food_group response = Mean / group = select_var  GroupDisplay = cluster  LimitLower = LowerCLMean  LimitUpper = UpperCLMean 	LimitAttrs = (Color = black);
	format sex sexfmt.  food_group fdgpfmt.  select_var ynfmt.  Mean F4.1  LowerCLMean F4.1  UpperCLMean F4.1; 
	scatter x = food_group  y = mean / group = select_var  GroupDisplay = cluster  DataLabel  DataLabelPos = right  DataLabelAttrs=(color=black)  MarkerAttrs=(size=0);
	scatter x = food_group  y = LowerCLMean / group = select_var  GroupDisplay = cluster  DataLabel  DataLabelPos = bottomright  DataLabelAttrs=(color=black)  MarkerAttrs=(size=0);
	scatter x = food_group  y = UpperCLMean / group = select_var  GroupDisplay = cluster  DataLabel  DataLabelPos = topright  DataLabelAttrs=(color=black) MarkerAttrs=(size=0);
	ColAxis display = (NoLabel); 
	RowAxis label = "Percents";
run; 

SGPanel116.png

 

As you can see, data labels of the means and lower limits are overlapping their own bars which is not very "clean". Is there a way to put these data labels under the bars as in the PROC SGPLOT output? 

Also, should I conclude that DATALABEL and LIMITLOWER/LIMITUPPER are indeed incompatible when using PROC SGPANEL?

Thank you again for your help 🙂

FreelanceReinh
Jade | Level 19

Hello @Mombi,

 

I think you can add the desired table by using the COLAXISTABLE statement:

 

proc sgpanel data = my_data_SGPANEL;
  panelby sex;
  vbarparm category = food_group response = Mean / group = select_var  groupdisplay = cluster  DataLabel  LimitLower = LowerCLMean  LimitUpper = UpperCLMean  LimitAttrs = (Color = black);
  format sex sexfmt.  food_group fdgpfmt.  select_var ynfmt.  Mean F4.1  LowerCLMean F4.1  UpperCLMean F4.1; 
  ColAxis display = (NoLabel); 
  RowAxis label = "Percents";
  colaxistable LowerCLMean Mean UpperCLMean / class=select_var classdisplay=cluster;
run; 

At least this works on my SAS 9.4M5 (where I do not get notes in the log about incompatibility of DATALABEL and error bars).

SGPANEL_COLAXISTABLE.png

 


@Mombi wrote:

 

NOTE: La barre d'erreur ne prend en charge l'option DATALABEL=. Le libellé ne sera pas ajouté.

(...) not sure where French is coming from here since all the other messages in my LOG are in English

You can obtain those special log messages in English by (temporarily) changing the value of the LOCALE system option:

options locale=EN_US;

 

Mombi
Fluorite | Level 6

Thanks a lot @FreelanceReinh: that's exactly what I wanted! Also, adding this COLAXISTABLE statement made the notes disappear. 

I was about to post a solution involving the creation of coordinate variables combined with some TEXT statements but your proposal is much more elegant 🙂

 

P.S. : In case it could help someone find this topic if the note pops up in their log, I have tried  "options locale = EN_US" and in English, the note is "Error bar does not support the DATALABEL= option. The label will not be drawn."

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 465 views
  • 2 likes
  • 3 in conversation