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

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 sgplotoutput of proc sgplot

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

Ksharp_0-1708058039650.png

 

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

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.)

Ksharp
Super User
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;

Ksharp_0-1708058039650.png

 

Ksharp
Super User

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;

Ksharp_1-1708058734312.png

 

Mathassens
Fluorite | Level 6
Thanks you for yours answers 🙂

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
  • 4 replies
  • 934 views
  • 7 likes
  • 3 in conversation