BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
twildone
Pyrite | Level 9

Hi....I am trying to create a donut graph and wondering if it is possible to order the subgroup as I believe the default is ascending and would like to change that. Thanks.

 

data Have;
    length Div $ 22 Reg $ 35 Dep $ 14 '2017-18'n 8 '2016-17'n 8;
    format Div $char22. Reg $char35. Dep $char14. '2017-18'n comma12. '2016-17'n comma12.;
    informat Div $char22. Reg $char35. Dep $char14. '2017-18'n comma12. '2016-17'n comma12.;
    infile datalines4 dlm='7F'x missover dsd;
    input Div : $char22. Reg : $char35. Dep : $char14. '2017-18'n : best32. '2016-17'n : best32.;
datalines4;
SecMHS 2226
SecSe 200170
PosELTESL403537
PosELTELI250126
PosYBYouthBuild3233
PosLLIAprrenticeship4249
PosLLIOLLI152172
PosAOP 12511089
AlcALC 9621013
;;;;

ods graphics on / reset=all  width=2.25in height=1.75in scale=off;

proc gchart data=Have;
   donut Reg  / sumvar='2017-18'n
                subgroup=Div
                noheading
                donutpct=22
			label=(h=0.7 color=black '2017-2018' justify=center 'New' justify=center 'Applicants' justify=center '(3,314)')
                nolegend
				discrete
                coutline=black
				value=inside
                ctext=black
				slice=inside
				detail_value=none
				detail_slice=none
				detail_threshold=2
				plabel=( h=0.7 color=black);
run;
quit;


ods pdf close;
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @twildone,

 

Sorry to see that your question hasn't been answered yet. I didn't know a solution off the top of my head, but thanks to your usable sample data and code I could develop and test my ideas easily.

 

You can define a format for variable Div whose labels in alphabetical order reflect the desired order of the internal values. For example, if you want to change the default (alphabetical) order "Alc, Pos, Sec" to "Sec, Pos, Alc", define a format like

proc format;
value $DivFmt
'Sec'='  Sec' /* two leading blanks */
'Pos'=' Pos'  /* one leading blank  */
'Alc'='Alc';  /* no  leading blank  */
run;

Then apply the format in the PROC GCHART step:

proc gchart data=Have;
   format Div $DivFmt.;
...

Now, the subgroups are sorted by the formatted values of Div, which are -- in alphabetical order -- "  Sec", " Pos" and "Alc". Luckily, SAS ignores the leading blanks in the output (but honors them when sorting the subgroups), so the labels in the graph look exactly as they should -- regardless of how many leading blanks we've inserted to tweak the sort order.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hi @twildone,

 

Sorry to see that your question hasn't been answered yet. I didn't know a solution off the top of my head, but thanks to your usable sample data and code I could develop and test my ideas easily.

 

You can define a format for variable Div whose labels in alphabetical order reflect the desired order of the internal values. For example, if you want to change the default (alphabetical) order "Alc, Pos, Sec" to "Sec, Pos, Alc", define a format like

proc format;
value $DivFmt
'Sec'='  Sec' /* two leading blanks */
'Pos'=' Pos'  /* one leading blank  */
'Alc'='Alc';  /* no  leading blank  */
run;

Then apply the format in the PROC GCHART step:

proc gchart data=Have;
   format Div $DivFmt.;
...

Now, the subgroups are sorted by the formatted values of Div, which are -- in alphabetical order -- "  Sec", " Pos" and "Alc". Luckily, SAS ignores the leading blanks in the output (but honors them when sorting the subgroups), so the labels in the graph look exactly as they should -- regardless of how many leading blanks we've inserted to tweak the sort order.

twildone
Pyrite | Level 9

Hi FreelanceReinhard….thank you for taking the time to responding to my problem. It worked....I never thought about entering blanks but was trying different things and even renaming the entries in Div so they appear in ascending order....Thanks once again...greatly appreciated

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 470 views
  • 0 likes
  • 2 in conversation