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;
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.
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.
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
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.