Morning,
I'm curious if anyone is aware of a seglabel option for positioning the label at the top of the bar? Currently the default appears to place the label in the middle of the bar. I'm using 9.4 M4.
Thanks,
Lucas
Maybe need change data for.
data test;
input patid $ ptstat;
datalines;
1 1
2 1
3 1
4 2
5 2
6 3
7 3
8 3
9 3
10 3
11 3
12 4
13 4
14 4
15 4
16 4
17 4
18 4
19 4
20 4
;
run;
proc freq data=test noprint;
table ptstat/ out=have ;
run;
data have;
set have;
_count=count-0.5;
run;
proc format;
value ptstatf 1='Active' 2='LTF/AC/WD' 3='Deceased with Autopsy' 4='Deceased without Autopsy';
quit;
title "Cohort Status (N=20)";
proc sgplot data=have noborder;
vbarparm category=ptstat response=count /fillattrs=(color=bib) barwidth=0.65 dataskin=matte ;
text x=ptstat y=_count text=count/ strip TEXTATTRS=(size=14 color=white) ;
xaxis label='Status' display=(noticks) labelattrs=(size=12 family=arial);
yaxis label='# Particpants' GRID VALUES = (0 TO 10 BY 2) labelattrs=(size=12 family=arial);
format ptstat ptstatf.;
run;
title;
Have you got some code to work from?
data test;
input patid $ ptstat;
datalines;
1 1
2 1
3 1
4 2
5 2
6 3
7 3
8 3
9 3
10 3
11 3
12 4
13 4
14 4
15 4
16 4
17 4
18 4
19 4
20 4
;
run;
proc format;
value ptstatf 1='Active' 2='LTF/AC/WD' 3='Deceased with Autopsy' 4='Deceased without Autopsy';
quit;
title "Cohort Status (N=20)";
proc sgplot data=test noborder;
vbar ptstat / fillattrs=(color=bib) barwidth=0.65 seglabel seglabelattrs=(size=12 family=arial color=white)
stat=sum dataskin=matte;
xaxis label='Status' display=(noticks) labelattrs=(size=12 family=arial);
yaxis label='# Particpants' GRID VALUES = (0 TO 10 BY 2) labelattrs=(size=12 family=arial);
format ptstat ptstatf.;
run;
title;
Does it have to be done with the seglabel option? If all you want is to place the label on top of the bar, you can use the Datalabel Option like this
title "Cohort Status (N=20)";
proc sgplot data=test noborder;
vbar ptstat / fillattrs=(color=bib) barwidth=0.65 datalabel datalabelpos=data datalabelattrs=(size=12 family=arial color=black)
stat=sum dataskin=matte;
xaxis label='Status' display=(noticks) labelattrs=(size=12 family=arial);
yaxis label='# Particpants' GRID VALUES = (0 TO 10 BY 2) labelattrs=(size=12 family=arial);
format ptstat ptstatf.;
run;
title;
I want the label at the top of the bar, inside the bar - not on top of bar. Does datalabel have this option?
No I dont think so. You can do a workaround doing something like this. Use VBARPARM instead of VBAR and use TEXT Statement to inset the labels. A bit overkill perhaps though...
data test;
input patid $ ptstat;
datalines;
1 1
2 1
3 1
4 2
5 2
6 3
7 3
8 3
9 3
10 3
11 3
12 4
13 4
14 4
15 4
16 4
17 4
18 4
19 4
20 4
;
run;
proc format;
value ptstatf 1='Active' 2='LTF/AC/WD' 3='Deceased with Autopsy' 4='Deceased without Autopsy';
quit;
proc sql;
create table stats as
select ptstat format=ptstatf.
,count(patid) as NumParticpants
,count(patid)-.5 as Position
from test
group by ptstat;
quit;
title "Cohort Status (N=20)";
proc sgplot data=stats noborder noautolegend;
vbarparm category=ptstat response=NumParticpants / fillattrs=(color=bib) barwidth=0.65 dataskin=matte;
text x=ptstat y=Position text=NumParticpants / position=left textattrs=(size=12 family=arial color=white);
xaxis label='Status' display=(noticks) labelattrs=(size=12 family=arial);
yaxis label='# Particpants' GRID VALUES = (0 TO 10 BY 2) labelattrs=(size=12 family=arial) offsetmin=0;
format ptstat ptstatf.;
run;
title;
Maybe need change data for.
data test;
input patid $ ptstat;
datalines;
1 1
2 1
3 1
4 2
5 2
6 3
7 3
8 3
9 3
10 3
11 3
12 4
13 4
14 4
15 4
16 4
17 4
18 4
19 4
20 4
;
run;
proc freq data=test noprint;
table ptstat/ out=have ;
run;
data have;
set have;
_count=count-0.5;
run;
proc format;
value ptstatf 1='Active' 2='LTF/AC/WD' 3='Deceased with Autopsy' 4='Deceased without Autopsy';
quit;
title "Cohort Status (N=20)";
proc sgplot data=have noborder;
vbarparm category=ptstat response=count /fillattrs=(color=bib) barwidth=0.65 dataskin=matte ;
text x=ptstat y=_count text=count/ strip TEXTATTRS=(size=14 color=white) ;
xaxis label='Status' display=(noticks) labelattrs=(size=12 family=arial);
yaxis label='# Particpants' GRID VALUES = (0 TO 10 BY 2) labelattrs=(size=12 family=arial);
format ptstat ptstatf.;
run;
title;
Thanks. Ksharp's method works but I do agree this is overkill. Seems like SAS should just implement an option within seglabel for this to make it a bit easier...
Yes, this is on our list of features, including an option to add a back light for easier visibility. It did not make it into the release due to schedule and priorities. While overlaying TextPlot is an option (includes back light), it required users to compute the position of each segment.
Separately, (just FYI) there is a BarLabelFitPolity=InsidePreferred for non grouped horizontal bars that will place a data label inside the bar at the top.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.