<?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 SAS not assigning colors to bars in correct order in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-not-assigning-colors-to-bars-in-correct-order/m-p/865677#M341855</link>
    <description>&lt;P&gt;Could someone please help me figure out why SAS is not assigning colors to my bar chart in the correct order? It is driving me crazy! I want colors to be assigned to each frequency level as I've written it out:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value imp_screening
1="Very unimportant"
2="A litte unimportant"
3="Neutral"
4="A litte important"
5="Very important"
6="I do not have a sense of this";
run;

proc sgplot data=IMP_COMB NOCYCLEATTRS noautolegend;
vbar cat /group = howoft GROUPDISPLAY = CLUSTER  fillattrs=howoft;
title 'Responses to: "Indicate the importance of screening for each of the following in primary care" (n=52)';
XAXIS DISPLAY=(NOLABEL);
keylegend / title=" ";
styleattrs datacolors=(CX8B0021 /*dark red*/ CXAB0532 /*light red*/  CX558DBD /*grey*/ CX002872 /*light blue*/ CXE2E9EB /*dark blue*/ CXF4EDE5 /*beige*/);
format cat screener. howoft imp_screening.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want neutral to be grey and a little unimportant to be light red, but it keeps switching them:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot17.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81918iE8C5F400E31A704B/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGPlot17.png" alt="SGPlot17.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;No matter what I do, as the picture shows, neutral is red and a little unimportant is grey. Please help, it is driving me crazy! I would also appreciate some help getting the key legend in the right order (very unimportant --&amp;gt; very important). Thanks so much!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2023 09:05:44 GMT</pubDate>
    <dc:creator>keherder</dc:creator>
    <dc:date>2023-03-22T09:05:44Z</dc:date>
    <item>
      <title>SAS not assigning colors to bars in correct order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-not-assigning-colors-to-bars-in-correct-order/m-p/865677#M341855</link>
      <description>&lt;P&gt;Could someone please help me figure out why SAS is not assigning colors to my bar chart in the correct order? It is driving me crazy! I want colors to be assigned to each frequency level as I've written it out:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value imp_screening
1="Very unimportant"
2="A litte unimportant"
3="Neutral"
4="A litte important"
5="Very important"
6="I do not have a sense of this";
run;

proc sgplot data=IMP_COMB NOCYCLEATTRS noautolegend;
vbar cat /group = howoft GROUPDISPLAY = CLUSTER  fillattrs=howoft;
title 'Responses to: "Indicate the importance of screening for each of the following in primary care" (n=52)';
XAXIS DISPLAY=(NOLABEL);
keylegend / title=" ";
styleattrs datacolors=(CX8B0021 /*dark red*/ CXAB0532 /*light red*/  CX558DBD /*grey*/ CX002872 /*light blue*/ CXE2E9EB /*dark blue*/ CXF4EDE5 /*beige*/);
format cat screener. howoft imp_screening.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want neutral to be grey and a little unimportant to be light red, but it keeps switching them:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot17.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81918iE8C5F400E31A704B/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGPlot17.png" alt="SGPlot17.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;No matter what I do, as the picture shows, neutral is red and a little unimportant is grey. Please help, it is driving me crazy! I would also appreciate some help getting the key legend in the right order (very unimportant --&amp;gt; very important). Thanks so much!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 09:05:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-not-assigning-colors-to-bars-in-correct-order/m-p/865677#M341855</guid>
      <dc:creator>keherder</dc:creator>
      <dc:date>2023-03-22T09:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS not assigning colors to bars in correct order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-not-assigning-colors-to-bars-in-correct-order/m-p/865693#M341860</link>
      <description>&lt;P&gt;Try sorting your data by the group variable.&lt;/P&gt;
&lt;P&gt;The colors tend to be assigned "first value encountered gets first data color".&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 10:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-not-assigning-colors-to-bars-in-correct-order/m-p/865693#M341860</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-22T10:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS not assigning colors to bars in correct order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-not-assigning-colors-to-bars-in-correct-order/m-p/865697#M341862</link>
      <description>&lt;P&gt;I think the attribute map should do the job:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods graphics / 
  height=5.5in 
  width=5.5in;

data imp_comb;
call streaminit(42);
do howoft = 1,6,3,4,5,2;
  do cat = "A","B","C";
    do i = 1 to rand("integer",0,3);
      output;
    end;
  end;
end; 
run;

proc format;
value imp_screening
1="Very unimportant"
2="A litte unimportant"
3="Neutral"
4="A litte important"
5="Very important"
6="I do not have a sense of this";
run;


data myattrmap;
  length fillcolor $ 20;
  input id $ v fillcolor $;
  linecolor = fillcolor;
  value = put(v,imp_screening.);
datalines;
myid 1 CX8B0021
myid 2 CXAB0532
myid 3 CX558DBD
myid 4 CX002872
myid 5 CXE2E9EB
myid 6 CXF4EDE5
;
run;
proc print;
run;


proc sgplot data=IMP_COMB NOCYCLEATTRS noautolegend dattrmap=myattrmap;
vbar cat / group = howoft GROUPDISPLAY = CLUSTER  /*fillattrs=howoft*/ attrid=myid;
title 'Responses to: "Indicate the importance of screening for each of the following in primary care" (n=52)';
XAXIS DISPLAY=(NOLABEL);
keylegend / title=" ";
format /*cat screener.*/ howoft imp_screening.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yabwon_0-1679482623141.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81921i2259425854382B99/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yabwon_0-1679482623141.png" alt="yabwon_0-1679482623141.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Search for "Discrete Attribute Map Data Sets" in the documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 10:57:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-not-assigning-colors-to-bars-in-correct-order/m-p/865697#M341862</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-03-22T10:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS not assigning colors to bars in correct order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-not-assigning-colors-to-bars-in-correct-order/m-p/865701#M341864</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
Change your format as the following.
a.k.a padding white blanks befor label
*/
proc format;
value imp_screening
1="     Very unimportant"
2="    A litte unimportant"
3="   Neutral"
4="  A litte important"
5=" Very important"
6="I do not have a sense of this";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Mar 2023 11:36:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-not-assigning-colors-to-bars-in-correct-order/m-p/865701#M341864</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-03-22T11:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS not assigning colors to bars in correct order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-not-assigning-colors-to-bars-in-correct-order/m-p/865795#M341905</link>
      <description>&lt;P&gt;Amazing, thanks so much for writing out all the code! Still haven't resolved the legend issue, but this fixed the color issue.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 20:40:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-not-assigning-colors-to-bars-in-correct-order/m-p/865795#M341905</guid>
      <dc:creator>keherder</dc:creator>
      <dc:date>2023-03-22T20:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: SAS not assigning colors to bars in correct order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-not-assigning-colors-to-bars-in-correct-order/m-p/865853#M341939</link>
      <description>&lt;P&gt;Try this and let me know if this is what you need:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data=IMP_COMB NOCYCLEATTRS noautolegend dattrmap=myattrmap;
vbar cat / group = howoft GROUPDISPLAY = CLUSTER  /*fillattrs=howoft*/ attrid=myid
GROUPORDER=ASCENDING /* &amp;lt;- NEW */
;
title 'Responses to: "Indicate the importance of screening for each of the following in primary care" (n=52)';
XAXIS DISPLAY=(NOLABEL);
keylegend / title=" ";
format /*cat screener.*/ howoft imp_screening.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 06:25:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-not-assigning-colors-to-bars-in-correct-order/m-p/865853#M341939</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-03-23T06:25:12Z</dc:date>
    </item>
  </channel>
</rss>

