<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: bar chart  x-axis  as defined order in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/bar-chart-x-axis-as-defined-order/m-p/659116#M20076</link>
    <description>&lt;P&gt;Instead of creating character variables with values like "&amp;lt;1" leave them as original ages and make a custom format to display them, or make them specific numeric values with appropriate format that displays the values as needed.&lt;/P&gt;
&lt;P&gt;One of many ways possible:&lt;/P&gt;
&lt;PRE&gt;proc format;
invalue afmt 
'&amp;lt;1'   =1
'1-4'  =2
'5-19' =3
'20-44'=4
'45-54'=5
'55-64'=6
'65-74'=7
'75-84'=8
'85+'  =9
;
value a_fmt
1 = '  &amp;lt;1'
2 = ' 1-4'
3 = ' 5-19'
4 = '20-44'
5 = '45-54'
6 = '55-64'
7 = '65-74'
8 = '75-84'
9 = '85+';
run;

data have;
input age afmt. group count PERCENT;
datalines;
&amp;lt;1  	0	29	100
1-4	    0	50	100
5-19	0	284	98
20-44	0	4285	93
45-54	0	1930	83
55-64	0	1570	76
65-74	0	728	70
75-84	0	290	68
85+	    0	156	74
1-4	    1	6	2
20-44	1	306	7
45-54	1	388	17
55-64	1	487	24
65-74	1	311	30
75-84	1	139	32
85+ 	1	56	26
;

proc sgplot data=have;
vbar age / response=Percent group= group 
              grouporder=data groupdisplay=stack  seglabel ;  
 *seglabel segment labels;
/*xaxis discreteorder=data;*/
format age a_fmt.;
yaxis grid values=(0 to 100 by 10) label="Percentage of Total with Group";
run;&lt;/PRE&gt;
&lt;P&gt;This uses a custom informat to read the age group text values into numeric values that order as desired.&lt;/P&gt;
&lt;P&gt;Also in many respects the formatted values are used and it is a good idea to pay attention to the sort order of the formatted values. You will find that '&amp;lt;1' is alphabetically after '1', similarly '5' is after '10' because the first characters are compared for ordering. So create an ' 5' instead of '5' to get the sort order correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course if you summarized some other data that had age as a numeric to create the data set one, then likely you should leave the values as numeric and use a custom numeric format to create the grouping values. The analysis and graphing procedures will generally honor formats used&amp;nbsp; to create groups of values. The raw data likely could have been used in this case.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Jun 2020 20:20:01 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-06-15T20:20:01Z</dc:date>
    <item>
      <title>bar chart  x-axis  as defined order</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/bar-chart-x-axis-as-defined-order/m-p/659109#M20074</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input age $5. group count PERCENT;
datalines;
&amp;lt;1  	0	29	100
1-4	    0	50	100
5-19	0	284	98
20-44	0	4285	93
45-54	0	1930	83
55-64	0	1570	76
65-74	0	728	70
75-84	0	290	68
85+	    0	156	74
1-4	    1	6	2
20-44	1	306	7
45-54	1	388	17
55-64	1	487	24
65-74	1	311	30
75-84	1	139	32
85+ 	1	56	26
;
run;
proc format;
value $afmt 
'&amp;lt;1' ='1'
'1-4'= '2'
'5-19'='3'
'20-44'='4'
'45-54'='5'
'55-64'='6'
'65-74'='7'
'75-84'='8'
'85+'='9'
;

 value $ a_fmt
 '1' = '&amp;lt;1'
 '2' ='1-4'
 '3' = '5-19'
'4' = '20-44'
'5' = '45-54'
'6' = '55-64'
'7' = '65-74'
'8' = '75-84'
'9' = '85+';
 run;

                                                                                                   
ods graphics on / width=10in height=9 in;
title "100% Stacked Bar Chart Ordered by Percentages";
proc sgplot data=one;
vbar age / response=Percent group= group 
              grouporder=data groupdisplay=stack  seglabel ;  
 *seglabel segment labels;
/*xaxis discreteorder=data;*/
			   format age $a_fmt.;
yaxis grid values=(0 to 100 by 10) label="Percentage of Total with Group";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I&amp;nbsp; show the bar chart in order: &amp;lt;1, 1-4, 5-19, 20-44, 45-54,....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jun 2020 19:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/bar-chart-x-axis-as-defined-order/m-p/659109#M20074</guid>
      <dc:creator>xinyao</dc:creator>
      <dc:date>2020-06-15T19:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: bar chart  x-axis  as defined order</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/bar-chart-x-axis-as-defined-order/m-p/659116#M20076</link>
      <description>&lt;P&gt;Instead of creating character variables with values like "&amp;lt;1" leave them as original ages and make a custom format to display them, or make them specific numeric values with appropriate format that displays the values as needed.&lt;/P&gt;
&lt;P&gt;One of many ways possible:&lt;/P&gt;
&lt;PRE&gt;proc format;
invalue afmt 
'&amp;lt;1'   =1
'1-4'  =2
'5-19' =3
'20-44'=4
'45-54'=5
'55-64'=6
'65-74'=7
'75-84'=8
'85+'  =9
;
value a_fmt
1 = '  &amp;lt;1'
2 = ' 1-4'
3 = ' 5-19'
4 = '20-44'
5 = '45-54'
6 = '55-64'
7 = '65-74'
8 = '75-84'
9 = '85+';
run;

data have;
input age afmt. group count PERCENT;
datalines;
&amp;lt;1  	0	29	100
1-4	    0	50	100
5-19	0	284	98
20-44	0	4285	93
45-54	0	1930	83
55-64	0	1570	76
65-74	0	728	70
75-84	0	290	68
85+	    0	156	74
1-4	    1	6	2
20-44	1	306	7
45-54	1	388	17
55-64	1	487	24
65-74	1	311	30
75-84	1	139	32
85+ 	1	56	26
;

proc sgplot data=have;
vbar age / response=Percent group= group 
              grouporder=data groupdisplay=stack  seglabel ;  
 *seglabel segment labels;
/*xaxis discreteorder=data;*/
format age a_fmt.;
yaxis grid values=(0 to 100 by 10) label="Percentage of Total with Group";
run;&lt;/PRE&gt;
&lt;P&gt;This uses a custom informat to read the age group text values into numeric values that order as desired.&lt;/P&gt;
&lt;P&gt;Also in many respects the formatted values are used and it is a good idea to pay attention to the sort order of the formatted values. You will find that '&amp;lt;1' is alphabetically after '1', similarly '5' is after '10' because the first characters are compared for ordering. So create an ' 5' instead of '5' to get the sort order correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course if you summarized some other data that had age as a numeric to create the data set one, then likely you should leave the values as numeric and use a custom numeric format to create the grouping values. The analysis and graphing procedures will generally honor formats used&amp;nbsp; to create groups of values. The raw data likely could have been used in this case.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jun 2020 20:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/bar-chart-x-axis-as-defined-order/m-p/659116#M20076</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-15T20:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: bar chart  x-axis  as defined order</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/bar-chart-x-axis-as-defined-order/m-p/659130#M20077</link>
      <description>Thank you so much! it works well!</description>
      <pubDate>Mon, 15 Jun 2020 20:49:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/bar-chart-x-axis-as-defined-order/m-p/659130#M20077</guid>
      <dc:creator>xinyao</dc:creator>
      <dc:date>2020-06-15T20:49:52Z</dc:date>
    </item>
  </channel>
</rss>

