<?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: How to change colors on bars? in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/How-to-change-colors-on-bars/m-p/213429#M7933</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Easiest way would be to compute a classifier column that has two values based on DIFF.&amp;nbsp; Then you can assign that as the GROUP role for the bar chart.&amp;nbsp; Alternatively, you could use the IFC or IFN function to assign such a value directly to the group role.&amp;nbsp; GROUP=ifc(diff &amp;gt;=0, 'Positive', 'Negative');&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, use the appropriate colors you need in the style colors. With SAS 9.4, you can use the DATACOLOR option on the BEGINGRAPH statement.&amp;nbsp;&amp;nbsp; To ensure Positive bars are always blue, use the DiscreteAttrMap.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 12 May 2015 12:38:13 GMT</pubDate>
    <dc:creator>Jay54</dc:creator>
    <dc:date>2015-05-12T12:38:13Z</dc:date>
    <item>
      <title>How to change colors on bars?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-change-colors-on-bars/m-p/213428#M7932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again. More questions regarding proc template.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to have diffrent colors on the bars depending on the values. For instance, I want color red on "negative" bars and color blue on "positive" bars. Right now I have the same colors for both bars:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="graph_avvik.jpg" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/10359_graph_avvik.jpg" width="450" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;0-17 bar should be red same with 26-35.&lt;/P&gt;&lt;P&gt;18-25 bar should be blue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help is appriciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;best regards&lt;/P&gt;&lt;P&gt;Johan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input CU_AGE $ MALGRUPPE REFERANSE DIFF;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;0-17 0.1 0.3 -0.6&lt;/P&gt;&lt;P&gt;18-25 0.2 0.1 0.2&lt;/P&gt;&lt;P&gt;26-35 0.4 0.6 -0.3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc template;&lt;/P&gt;&lt;P&gt;define statgraph profile_age;&lt;/P&gt;&lt;P&gt;dynamic _NEGATIVE_;&lt;/P&gt;&lt;P&gt;dynamic _ticklist_;&lt;/P&gt;&lt;P&gt;begingraph /;&lt;/P&gt;&lt;P&gt;entrytitle "";&lt;/P&gt;&lt;P&gt;layout overlay / xaxisopts=( griddisplay=on Label="% av målgruppe" /*offsetmin=0*/ type=linear ) yaxisopts=( reverse=true display=( ticks tickvalues line ) type=discrete ) y2axisopts=(reverse=true);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if (_NEGATIVE_)&amp;nbsp;&amp;nbsp; ReferenceLine x=0 / lineattrs=GraphAxisLines;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; endif;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; barchart X='CU_AGE'n Y=DIFF / primary=true orient=horizontal LegendLabel="Aldersgruppe" NAME="a" dataskin=PRESSED&amp;nbsp; target=REFERANSE barlabel=true barwidth=0.1 BASELINEINTERCEPT=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; /*ScatterPlot X='TARGET'n Y='CU_GENDER'n / discreteOffset=-0.35 Markerattrs=( Symbol=TRIANGLEDOWNFILLED Size=10) DataTransparency=0.4 LegendLabel="normale population" NAME="t";*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; DiscreteLegend "a" "t" / Location=outside Title="";&lt;/P&gt;&lt;P&gt;endlayout;&lt;/P&gt;&lt;P&gt;endgraph;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;ods graphics on / height=500px width=600px;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;proc sgrender data=work.test template=profile_age;&lt;/P&gt;&lt;P&gt; format DIFF&amp;nbsp; percent12.1;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;ods graphics off;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 May 2015 11:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-change-colors-on-bars/m-p/213428#M7932</guid>
      <dc:creator>JohanFu</dc:creator>
      <dc:date>2015-05-12T11:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to change colors on bars?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-change-colors-on-bars/m-p/213429#M7933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Easiest way would be to compute a classifier column that has two values based on DIFF.&amp;nbsp; Then you can assign that as the GROUP role for the bar chart.&amp;nbsp; Alternatively, you could use the IFC or IFN function to assign such a value directly to the group role.&amp;nbsp; GROUP=ifc(diff &amp;gt;=0, 'Positive', 'Negative');&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, use the appropriate colors you need in the style colors. With SAS 9.4, you can use the DATACOLOR option on the BEGINGRAPH statement.&amp;nbsp;&amp;nbsp; To ensure Positive bars are always blue, use the DiscreteAttrMap.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 May 2015 12:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-change-colors-on-bars/m-p/213429#M7933</guid>
      <dc:creator>Jay54</dc:creator>
      <dc:date>2015-05-12T12:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to change colors on bars?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-change-colors-on-bars/m-p/213430#M7934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We have only SAS 9.3. Is it still possible?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have now this dataset:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="graph_avvik_2.jpg" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/10361_graph_avvik_2.jpg" width="450" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what is my next step?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 May 2015 13:24:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-change-colors-on-bars/m-p/213430#M7934</guid>
      <dc:creator>JohanFu</dc:creator>
      <dc:date>2015-05-12T13:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to change colors on bars?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-change-colors-on-bars/m-p/213431#M7935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Assign the GROUP column to the GROUP role in the bar chart.&amp;nbsp; You will get the first two colors from the current style, based on which valued is first in the data.&amp;nbsp; To ensure Positive is always Blue, use the DiscreteAttrMap.&amp;nbsp; This is the right way to ensure correct color assignment.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternatively, add two dummy observations to the top of your data, with missing CU_AGE, first one having "Positive" and second one having "Negative" values for the GROUP variable.&amp;nbsp; This will ensure the first group color (generally blue) will be assigned to "Positive", and second group color (generally light red) will be assigned to "Negative". &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 May 2015 13:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-change-colors-on-bars/m-p/213431#M7935</guid>
      <dc:creator>Jay54</dc:creator>
      <dc:date>2015-05-12T13:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to change colors on bars?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-change-colors-on-bars/m-p/213432#M7936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; sir&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 May 2015 07:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-change-colors-on-bars/m-p/213432#M7936</guid>
      <dc:creator>JohanFu</dc:creator>
      <dc:date>2015-05-13T07:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to change colors on bars?</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-to-change-colors-on-bars/m-p/213433#M7937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you it works &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the code for those who wants them &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input CU_AGE $ MALGRUPPE REFERANSE DIFF;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;0-17 0.1 0.3 -0.6&lt;/P&gt;&lt;P&gt;18-25 0.2 0.1 0.2&lt;/P&gt;&lt;P&gt;26-35 0.4 0.6 -0.3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; GROUP=ifc(DIFF&amp;gt;=0, 'Positive', 'Negative'); &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc template;&lt;/P&gt;&lt;P&gt;define statgraph profile_age;&lt;/P&gt;&lt;P&gt;dynamic _NEGATIVE_;&lt;/P&gt;&lt;P&gt;dynamic _ticklist_;&lt;/P&gt;&lt;P&gt;begingraph /;&lt;/P&gt;&lt;P&gt;entrytitle "";&lt;/P&gt;&lt;P&gt; discreteattrmap name='colors' / ignorecase=true;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value "Positive" / fillattrs=(color=blue);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value "Negative" / fillattrs=(color=red);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; enddiscreteattrmap;&lt;/P&gt;&lt;P&gt;discreteattrvar attrvar=barcolors var=group attrmap='colors';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;layout overlay / xaxisopts=( griddisplay=on Label="% av målgruppe" /*offsetmin=0*/ type=linear ) yaxisopts=( reverse=true display=( ticks tickvalues line ) type=discrete ) y2axisopts=(reverse=true);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if (_NEGATIVE_)&amp;nbsp;&amp;nbsp; ReferenceLine x=0 / lineattrs=GraphAxisLines;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; endif;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; barchart X='CU_AGE'n Y=DIFF / primary=true orient=horizontal LegendLabel="Aldersgruppe" NAME="a" dataskin=PRESSED&amp;nbsp; target=REFERANSE barlabel=true barwidth=0.1 BASELINEINTERCEPT=0 group=barcolors;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; /*ScatterPlot X='TARGET'n Y='CU_GENDER'n / discreteOffset=-0.35 Markerattrs=( Symbol=TRIANGLEDOWNFILLED Size=10) DataTransparency=0.4 LegendLabel="normale population" NAME="t";*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; DiscreteLegend "a" "t" / Location=outside Title="";&lt;/P&gt;&lt;P&gt;endlayout;&lt;/P&gt;&lt;P&gt;endgraph;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ods graphics on / height=500px width=600px;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sgrender data=work.test template=profile_age;&lt;/P&gt;&lt;P&gt; format DIFF&amp;nbsp; percent12.1;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ods graphics off;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 May 2015 10:15:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-to-change-colors-on-bars/m-p/213433#M7937</guid>
      <dc:creator>JohanFu</dc:creator>
      <dc:date>2015-05-13T10:15:59Z</dc:date>
    </item>
  </channel>
</rss>

