<?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 Other Category for Stacked Bar Chart in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Other-Category-for-Stacked-Bar-Chart/m-p/776772#M22194</link>
    <description>&lt;P&gt;I'm having trouble creating the 'Other' category for smaller groups in my data for a stacked bar.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data is grouped by a year/month variable then by a product variable:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Keegan_0-1635347731284.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65084iEB4D70743D6701C7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Keegan_0-1635347731284.png" alt="Keegan_0-1635347731284.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried this code to group:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt; %let topN=5;

data other;
	set term_sum;
	label topcat='Product Group';
	topcat=prod_group;
	if _n_ &amp;gt; &amp;amp;topn then topcat='Other'; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, this code only takes into account the prod_group variable, and not the yy_mm variable. And the grouping looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Keegan_1-1635347931642.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65085i4CE5C5D5D499DC06/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Keegan_1-1635347931642.png" alt="Keegan_1-1635347931642.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's only looking at the prod_group and the top 5 and ignoring the parent group of yy_mm.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like this doesn't work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data other;
	set term_out;
	label topcat='Product Group';
	&lt;FONT color="#FF0000"&gt;topcat=yy_mm*prod_group;&lt;/FONT&gt;
	if _n_ &amp;gt; &amp;amp;topn then topcat='Other'; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Are there suggestions to group together within my year/month grouping?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I could use the sgplot to plot the results:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sgplot data=term_out;
  title 'Test Chart';
  vbar yy_mm / response=count group=prod_group dataskin=gloss;
  xaxis display=(nolabel);
  yaxis grid;
  run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It needs to be dynamic, since this will be automated and the groups that are the top 5 could change.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, you'll notice there is a grouping of 'Other' already, but that just happened to be the name of the group.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Oct 2021 15:23:35 GMT</pubDate>
    <dc:creator>Keegan</dc:creator>
    <dc:date>2021-10-27T15:23:35Z</dc:date>
    <item>
      <title>Other Category for Stacked Bar Chart</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Other-Category-for-Stacked-Bar-Chart/m-p/776772#M22194</link>
      <description>&lt;P&gt;I'm having trouble creating the 'Other' category for smaller groups in my data for a stacked bar.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data is grouped by a year/month variable then by a product variable:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Keegan_0-1635347731284.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65084iEB4D70743D6701C7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Keegan_0-1635347731284.png" alt="Keegan_0-1635347731284.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried this code to group:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt; %let topN=5;

data other;
	set term_sum;
	label topcat='Product Group';
	topcat=prod_group;
	if _n_ &amp;gt; &amp;amp;topn then topcat='Other'; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, this code only takes into account the prod_group variable, and not the yy_mm variable. And the grouping looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Keegan_1-1635347931642.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65085i4CE5C5D5D499DC06/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Keegan_1-1635347931642.png" alt="Keegan_1-1635347931642.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's only looking at the prod_group and the top 5 and ignoring the parent group of yy_mm.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like this doesn't work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data other;
	set term_out;
	label topcat='Product Group';
	&lt;FONT color="#FF0000"&gt;topcat=yy_mm*prod_group;&lt;/FONT&gt;
	if _n_ &amp;gt; &amp;amp;topn then topcat='Other'; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Are there suggestions to group together within my year/month grouping?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I could use the sgplot to plot the results:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sgplot data=term_out;
  title 'Test Chart';
  vbar yy_mm / response=count group=prod_group dataskin=gloss;
  xaxis display=(nolabel);
  yaxis grid;
  run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It needs to be dynamic, since this will be automated and the groups that are the top 5 could change.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, you'll notice there is a grouping of 'Other' already, but that just happened to be the name of the group.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 15:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Other-Category-for-Stacked-Bar-Chart/m-p/776772#M22194</guid>
      <dc:creator>Keegan</dc:creator>
      <dc:date>2021-10-27T15:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Other Category for Stacked Bar Chart</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Other-Category-for-Stacked-Bar-Chart/m-p/776793#M22195</link>
      <description>&lt;P&gt;Please provide a concise definition of what "Other" should be. If the prod_group VALUES that are to be included change from month to month this not going to be a bit more of an exercise. Such as you have to do whatever analysis by the "dates".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide example data in the form of data step code that includes at least two "months". BTW, it appears from the picture that your&amp;nbsp; YY_mm variable is character which is very often sub-optimal because there are many tools to work with actual dates that make things much more flexible (or dynamic) &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code sets all values to 'Other' after line 5. This is because the variable _n_ counts iterations of the data step, which for many means the row of the data. If you meant to use the value of Count that you show in the PICTURE then perhaps this would work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data other;
	set term_sum;
	label topcat='Product Group';
	topcat=prod_group;
	if count &amp;gt; &amp;amp;topn then topcat='Other'; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course this doesn't work. You are attempting to multiply two CHARACTER values. You can COMBINE two character values with a concatenation. Plus you are still using the _n_ wh&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;It's only looking at the prod_group and the top 5 and ignoring the parent group of yy_mm.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this doesn't work:&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data other;
	set term_out;
	label topcat='Product Group';
	&lt;FONT color="#FF0000"&gt;topcat=yy_mm*prod_group;&lt;/FONT&gt;
	if _n_ &amp;gt; &amp;amp;topn then topcat='Other'; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 16:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Other-Category-for-Stacked-Bar-Chart/m-p/776793#M22195</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-27T16:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: Other Category for Stacked Bar Chart</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Other-Category-for-Stacked-Bar-Chart/m-p/776821#M22196</link>
      <description>&lt;P&gt;Thanks for responding!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Though I just solved the issue by simply using a proc rank and redefining the variables based on that. It adds another step, but it's easy to understand for me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 17:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Other-Category-for-Stacked-Bar-Chart/m-p/776821#M22196</guid>
      <dc:creator>Keegan</dc:creator>
      <dc:date>2021-10-27T17:26:24Z</dc:date>
    </item>
  </channel>
</rss>

