Data visualization with SAS programming

Bar chart with sgplot

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

Bar chart with sgplot

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,


bar chart.png

Accepted Solutions
Solution
‎06-29-2017 07:42 AM
Super User
Super User
Posts: 7,711

Re: Bar chart with sgplot

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.

View solution in original post


All Replies
Contributor
Posts: 26

Bar chart with Sgplot

 

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,


bar chart.png
Super User
Super User
Posts: 7,711

Re: Bar chart with sgplot

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.

Contributor
Posts: 26

Re: Bar chart with sgplot

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;

Solution
‎06-29-2017 07:42 AM
Super User
Super User
Posts: 7,711

Re: Bar chart with sgplot

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.

Contributor
Posts: 26

Re: Bar chart with sgplot

Thank you

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 223 views
  • 0 likes
  • 2 in conversation