Dear all,
I would like to change the labels of each bar but keeping same order of procedure.
Please find my code:
proc sgplot data=toto noborder;
styleattrs datacolors=(Firebrick big vpap deepskyblue ) ;
vbar patient / response=time /*stat=sum*/
group=procedure fil barwidth=0.2 seglabel seglabelattrs=(color=white size=12 ) /*datalabel*/
baselineattrs=(thickness=0 ) groupdisplay=stack
outlineattrs=(color=cx3f3f3f);
keylegend / position=right;
xaxis display=(nolabel noline noticks);
yaxis label='Hours' grid;
title 'Procedure times';
run;
Please find below the graph inside attachments.
I would like to replace:
'01:Induction' by 'Induction'
'02:Incis_CPB' by 'Incision to CPB'
'03:CPBDurati' by 'CPB duration'
'04:skin_clos' by CPB stop to skin closure
Thank all for your support,
Its a good idea to indicate "what doesn't work" in future. I guess its because you didn't apply the format:
proc format lib=work; value $procedure '01:Induction' = 'Induction' '02:Incis_CPB' = 'Incision to CPB' '03:CPBDurati' = 'Incision to CPB' '04:skin_clos' = 'CPB stop to skin closure'; run; title 'Procedure times'; proc sgplot data=toto noborder; styleattrs datacolors=(Firebrick big vpap deepskyblue ) ; vbar patient / response=time group=procedure barwidth=0.2 seglabel seglabelattrs=(color=white size=10) baselineattrs=(thickness=0 ) nooutline outlineattrs=(color=cx3f3f3f); format procedure $procedure.; keylegend / position=right; xaxis display=(nolabel noline noticks); yaxis label='Hours' grid; run;
Note the format line.
Dear all,
I would like to change the labels of each bar but keeping same order of procedure.
Please find my code:
proc sgplot data=toto noborder;
styleattrs datacolors=(Firebrick big vpap deepskyblue ) ;
vbar patient / response=time /*stat=sum*/
group=procedure fil barwidth=0.2 seglabel seglabelattrs=(color=white size=12 ) /*datalabel*/
baselineattrs=(thickness=0 ) groupdisplay=stack
outlineattrs=(color=cx3f3f3f);
keylegend / position=right;
xaxis display=(nolabel noline noticks);
yaxis label='Hours' grid;
title 'Procedure times';
run;
Please find below the graph inside attachments.
I would like to replace:
'01:Induction' by 'Induction'
'02:Incis_CPB' by 'Incision to CPB'
'03:CPBDurati' by 'CPB duration'
'04:skin_clos' by CPB stop to skin closure
Thank all for your support,
The way to do this is to make your categories numeric, i.e. 1 for the first, 2 for the second etc. and apply a format to them with the full text. This way the data orders correctly per the numeric, and displays the full formatted value.
I do not used very often proc format.
I try this code but that does not work:
proc format lib=work;
value $ procedure '01:Induction' = 'Induction'
'02:Incis_CPB' = 'Incision to CPB'
'03:CPBDurati' = 'Incision to CPB'
'04:skin_clos' = 'CPB stop to skin closure';
run;
proc sgplot data=toto noborder;
styleattrs datacolors=(Firebrick big vpap deepskyblue ) ;
vbar patient / response=time /*stat=sum*/
group=procedure barwidth=0.2 seglabel seglabelattrs=(color=white size=10) /*datalabel*/
baselineattrs=(thickness=0 ) nooutline /*groupdisplay=stack*/
outlineattrs=(color=cx3f3f3f);
Format procedure;
keylegend / position=right;
xaxis display=(nolabel noline noticks);
yaxis label='Hours' grid;
title 'Procedure times';
run;
Its a good idea to indicate "what doesn't work" in future. I guess its because you didn't apply the format:
proc format lib=work; value $procedure '01:Induction' = 'Induction' '02:Incis_CPB' = 'Incision to CPB' '03:CPBDurati' = 'Incision to CPB' '04:skin_clos' = 'CPB stop to skin closure'; run; title 'Procedure times'; proc sgplot data=toto noborder; styleattrs datacolors=(Firebrick big vpap deepskyblue ) ; vbar patient / response=time group=procedure barwidth=0.2 seglabel seglabelattrs=(color=white size=10) baselineattrs=(thickness=0 ) nooutline outlineattrs=(color=cx3f3f3f); format procedure $procedure.; keylegend / position=right; xaxis display=(nolabel noline noticks); yaxis label='Hours' grid; run;
Note the format line.
Thank you
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.