Using SAS 9.4
I am running the code below. A proc print of my aggregated data is below as well. My question is, when I run this I cannot seem to get my "label" variable to display on the graph. Would anyone know if there is an option I am missing when trying to label my data?
Obs | Timeperiod | category | Frequency | PERCENT | label |
---|---|---|---|---|---|
1 | Consultation | B-Lost 10-19.99 lbs | -117 | 45.7031 | 117 ( 45.7 %) |
2 | Consultation | C-Lost 20-29.99 lbs | -70 | 27.3438 | 70 ( 27.3 %) |
3 | Consultation | D-Lost >=30 lbs | -69 | 26.9531 | 69 ( 27.0 %) |
4 | Most Recent | G-Gained 10-19.99 lbs | 9 | 3.5156 | 9 ( 3.5 %) |
5 | Most Recent | H-Gained 20-29.99 lbs | 3 | 1.1719 | 3 ( 1.2 %) |
6 | Most Recent | F-Gained <10 lbs | 21 | 8.2031 | 21 ( 8.2 %) |
7 | Most Recent | I-Gained >30 lbs | 8 | 3.1250 | 8 ( 3.1 %) |
8 | Most Recent | B-Lost 10-19.99 lbs | 47 | 18.3594 | 47 ( 18.4 %) |
9 | Most Recent | C-Lost 20-29.99 lbs | 43 | 16.7969 | 43 ( 16.8 %) |
10 | Most Recent | A-Lost <10 lbs | 30 | 11.7188 | 30 ( 11.7 %) |
11 | Most Recent | D-Lost >=30 lbs | 93 | 36.3281 | 93 ( 36.3 %) |
12 | Most Recent | E-No Weight Change | 2 | 0.7813 | 2 ( 0.8 %) |
data freq_combined;
set freq_combined;
label = catx(' ', put(abs(frequency), 8.), '(', put(percent, 5.1), '%)');
run;
proc sgplot data=bl.butterfly;
format category $newcatfmt.;
hbar category / response=frequency group=timeperiod grouporder=descending barwidth=0.8 seglabel SEGLABELATTRS=(color=white size=8) seglabelfitpolicy=noclip dataskin=crisp;
styleattrs datacolors=(black teal);
xaxis label='Frequency' values=(-120 to 120 by 10);
yaxis label='Weight Change Categories';
xaxis values=(-120 -110 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120)
valuesdisplay=("120" "110" "100" "90" "80" "70" "60" "50" "40" "30" "20" "10" "0" "10" "20" "30" "40" "50" "60" "70" "80" "90" "100" "110" "120") FITPOLICY=STAGGER;
title;
keylegend / location=outside position=top fillheight=10 fillaspect=2;
run;
As you can see my code produces "-117" on the graph, when I would like it to show "117". Thank you
Try creating custom format using the LABEL information and attach that to the segment labels using the SEGLABELFORMAT
data formatcntlin; set freq_combined; fmtname='MySegLabel'; type='N'; start= frequency; /*you already have a Label variable*/ run; proc format cntlin=formatcntlin; run;
Then modify the HBAR statement to include:
seglabelformat=myseglabel.
OR use the format for the Frequency variable.
Try creating custom format using the LABEL information and attach that to the segment labels using the SEGLABELFORMAT
data formatcntlin; set freq_combined; fmtname='MySegLabel'; type='N'; start= frequency; /*you already have a Label variable*/ run; proc format cntlin=formatcntlin; run;
Then modify the HBAR statement to include:
seglabelformat=myseglabel.
OR use the format for the Frequency variable.
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.