BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PSIOT
SAS Employee

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
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

5 REPLIES 5
PSIOT
SAS Employee
 

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
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

PSIOT
SAS Employee

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;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

PSIOT
SAS Employee

Thank you

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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