Hello,
I would want to know if it's possible to change the font weight of a specific label of a bar chart.
My dataset is in an excel file.
My code is this currently this one:
proc sgplot data=FINAL_RMT noborder ;
format pctn1 percentn.1 ;
hbar SRS_LIB_RGP_STD_COL_N2 / response=pctn1 group=SRS_LIB_TYP_ASS /*displaybaseline=auto*/ barwidth=0.6
seglabel /*datalabel*/ seglabelattrs=(size=10pt color=white) dataskin=pressed legendlabel="";
yaxis display=(noline noticks nolabel) values=("EFFECTIFS" "TOTAL POSTES" "Soins courants" "Pharmacie" "Optique" "Hospitalisation" "Dentaire" "Autres") valueattrs=(size=12pt);
xaxis display=none ;
keylegend / /*exclude=*/ location=outside position=bottomleft fillheight=10 fillaspect=2 noborder title="" valueattrs=(size=12pt) ;
run;
I would have to have EFFECTIFS in bold if it's possible.
output of proc sgplot
proc import datafile='c:\temp\FINAL_RMT.xlsx' out=have dbms=xlsx replace;
run;
data dattrmap;
length textweight $10;
id='text'; value='EFFECTIFS'; textcolor='Black';textweight='bold'; output;
run;
proc sgplot data=have dattrmap=dattrmap;
format pctn1 percent7.1 ;
hbarparm category=SRS_LIB_RGP_STD_COL_N2 response=PCTN1/group=SRS_LIB_TYP_ASS barwidth=0.6 dataskin=pressed
seglabel seglabelattrs=(size=10pt color=white) SEGLABELFITPOLICY=none ;
yaxistable SRS_LIB_RGP_STD_COL_N2 / location=outside position=left
textgroup=SRS_LIB_RGP_STD_COL_N2 label=' ' textgroupid=text
VALUEATTRS=(size=10pt) VALUEJUSTIFY=right;
yaxis display=(nolabel novalues);
run;
Hello @Mathassens,
I think you can supply the individual label via an annotation dataset like this:
data anno;
function="text";
drawspace="datavalue";
x1=-0.105;
yc1="EFFECTIFS";
label="EFFECTIFS";
textweight="bold";
textsize=12;
width=50;
discreteoffset=-0.01;
run;
and then use the VALUESDISPLAY= option of the YAXIS statement to suppress the original label:
proc sgplot data=FINAL_RMT noborder sganno=anno; format pctn1 percentn.1 ; hbar SRS_LIB_RGP_STD_COL_N2 / response=pctn1 group=SRS_LIB_TYP_ASS /*displaybaseline=auto*/ barwidth=0.6 seglabel /*datalabel*/ seglabelattrs=(size=10pt color=white) dataskin=pressed legendlabel=""; yaxis display=(noline noticks nolabel) values=("EFFECTIFS" "TOTAL POSTES" "Soins courants" "Pharmacie" "Optique" "Hospitalisation" "Dentaire" "Autres") valueattrs=(size=12pt) valuesdisplay=(" " "TOTAL POSTES" "Soins courants" "Pharmacie" "Optique" "Hospitalisation" "Dentaire" "Autres"); xaxis display=none ; keylegend / /*exclude=*/ location=outside position=bottomleft fillheight=10 fillaspect=2 noborder title="" valueattrs=(size=12pt) ; run;
(That said, I wouldn't be surprised if one of the graph experts suggested a more elegant solution.)
proc import datafile='c:\temp\FINAL_RMT.xlsx' out=have dbms=xlsx replace;
run;
data dattrmap;
length textweight $10;
id='text'; value='EFFECTIFS'; textcolor='Black';textweight='bold'; output;
run;
proc sgplot data=have dattrmap=dattrmap;
format pctn1 percent7.1 ;
hbarparm category=SRS_LIB_RGP_STD_COL_N2 response=PCTN1/group=SRS_LIB_TYP_ASS barwidth=0.6 dataskin=pressed
seglabel seglabelattrs=(size=10pt color=white) SEGLABELFITPOLICY=none ;
yaxistable SRS_LIB_RGP_STD_COL_N2 / location=outside position=left
textgroup=SRS_LIB_RGP_STD_COL_N2 label=' ' textgroupid=text
VALUEATTRS=(size=10pt) VALUEJUSTIFY=right;
yaxis display=(nolabel novalues);
run;
If you want SEGLABEL be BOLD, could try this one:
proc import datafile='c:\temp\FINAL_RMT.xlsx' out=have dbms=xlsx replace;
run;
data want;
set have;
by SRS_LIB_RGP_STD_COL_N2 notsorted;
if first.SRS_LIB_RGP_STD_COL_N2 then cum=0;
x=cum+PCTN1/2;
cum+PCTN1;
format PCTN1 percent8.2;
if SRS_LIB_RGP_STD_COL_N2='EFFECTIFS' then do;x1=x;x=.;end;
run;
proc sgplot data=want;
hbarparm category=SRS_LIB_RGP_STD_COL_N2 response=PCTN1/group=SRS_LIB_TYP_ASS barwidth=0.6 dataskin=pressed;
text x=x1 y=SRS_LIB_RGP_STD_COL_N2 text=PCTN1/strip contributeoffsets=none textattrs=(size=12pt color=white weight=bold);
text x=x y=SRS_LIB_RGP_STD_COL_N2 text=PCTN1/strip contributeoffsets=none textattrs=(size=10pt color=white weight=normal);
yaxis display=(nolabel );
run;
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: