<?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 PROC GCHAR  HBAR Color based on variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/556087#M9760</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am using PROC GCHART and am trying to change the pattern color of my HBAR depending on a variable..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am posting my code below...&lt;/P&gt;&lt;P&gt;Based on the variable FallRed being 1 or 0&amp;nbsp; will determine if my bar color should be red = 1 or green &amp;lt;&amp;gt; 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot figure out how to incorporate my FallRed 1,0 into my pattern statement to change the color of my bar depending on the 1 or 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Want; set Have;&lt;/P&gt;&lt;P&gt;if (floor = 'Floor 2'&lt;BR /&gt;or floor = 'Floor 3'&lt;BR /&gt;or floor = 'Floor 4'&lt;BR /&gt;AND Fall7 &amp;gt; &amp;amp;falltarget)&lt;BR /&gt;then FallRed = 1;&lt;BR /&gt;else FallRed = 0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;goptions reset=all device=javaimg xpixels=300 ypixels=220; /*required for dial output */&lt;/P&gt;&lt;P&gt;pattern1 color=Red;/*controls floor 2 bar color */&lt;BR /&gt;pattern2 color=Red;/*controls floor 3 bar color */&lt;BR /&gt;pattern3 color=Red;/*controls floor 4 bar color */&lt;BR /&gt;Axis1&lt;BR /&gt;STYLE=1&lt;BR /&gt;WIDTH=1&lt;BR /&gt;LABEL=NONE /*shows label on axis */&lt;BR /&gt;order=("Floor 2" "Floor 3" "Floor 4")&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;Axis2&lt;BR /&gt;STYLE=0&lt;BR /&gt;WIDTH=1&lt;BR /&gt;MAJOR=NONE /*shows major tick marks */&lt;BR /&gt;MINOR=NONE /*shows minor tick marks */&lt;BR /&gt;LABEL=NONE /*shows label on axis */&lt;BR /&gt;VALUE=NONE&lt;BR /&gt;;&lt;BR /&gt;TITLE &amp;amp;titlstuf "Number of Falls (Last 7 Days)";&lt;BR /&gt;PROC GCHART DATA=HAVE&lt;BR /&gt;;&lt;BR /&gt;HBAR&lt;BR /&gt;Floor&lt;BR /&gt;/discrete type=sum&lt;BR /&gt;SUMVAR=Fall7 patternid=midpoint&lt;BR /&gt;CLIPREF&lt;BR /&gt;space=10&lt;BR /&gt;NOFRAME TYPE=SUM&lt;BR /&gt;OUTSIDE=SUM&lt;BR /&gt;COUTLINE=SAME&lt;BR /&gt;MAXIS=AXIS1&lt;BR /&gt;RAXIS=AXIS2&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 May 2019 19:47:01 GMT</pubDate>
    <dc:creator>zdeb15</dc:creator>
    <dc:date>2019-05-03T19:47:01Z</dc:date>
    <item>
      <title>PROC GCHAR  HBAR Color based on variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/556087#M9760</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am using PROC GCHART and am trying to change the pattern color of my HBAR depending on a variable..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am posting my code below...&lt;/P&gt;&lt;P&gt;Based on the variable FallRed being 1 or 0&amp;nbsp; will determine if my bar color should be red = 1 or green &amp;lt;&amp;gt; 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot figure out how to incorporate my FallRed 1,0 into my pattern statement to change the color of my bar depending on the 1 or 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Want; set Have;&lt;/P&gt;&lt;P&gt;if (floor = 'Floor 2'&lt;BR /&gt;or floor = 'Floor 3'&lt;BR /&gt;or floor = 'Floor 4'&lt;BR /&gt;AND Fall7 &amp;gt; &amp;amp;falltarget)&lt;BR /&gt;then FallRed = 1;&lt;BR /&gt;else FallRed = 0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;goptions reset=all device=javaimg xpixels=300 ypixels=220; /*required for dial output */&lt;/P&gt;&lt;P&gt;pattern1 color=Red;/*controls floor 2 bar color */&lt;BR /&gt;pattern2 color=Red;/*controls floor 3 bar color */&lt;BR /&gt;pattern3 color=Red;/*controls floor 4 bar color */&lt;BR /&gt;Axis1&lt;BR /&gt;STYLE=1&lt;BR /&gt;WIDTH=1&lt;BR /&gt;LABEL=NONE /*shows label on axis */&lt;BR /&gt;order=("Floor 2" "Floor 3" "Floor 4")&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;Axis2&lt;BR /&gt;STYLE=0&lt;BR /&gt;WIDTH=1&lt;BR /&gt;MAJOR=NONE /*shows major tick marks */&lt;BR /&gt;MINOR=NONE /*shows minor tick marks */&lt;BR /&gt;LABEL=NONE /*shows label on axis */&lt;BR /&gt;VALUE=NONE&lt;BR /&gt;;&lt;BR /&gt;TITLE &amp;amp;titlstuf "Number of Falls (Last 7 Days)";&lt;BR /&gt;PROC GCHART DATA=HAVE&lt;BR /&gt;;&lt;BR /&gt;HBAR&lt;BR /&gt;Floor&lt;BR /&gt;/discrete type=sum&lt;BR /&gt;SUMVAR=Fall7 patternid=midpoint&lt;BR /&gt;CLIPREF&lt;BR /&gt;space=10&lt;BR /&gt;NOFRAME TYPE=SUM&lt;BR /&gt;OUTSIDE=SUM&lt;BR /&gt;COUTLINE=SAME&lt;BR /&gt;MAXIS=AXIS1&lt;BR /&gt;RAXIS=AXIS2&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 19:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/556087#M9760</guid>
      <dc:creator>zdeb15</dc:creator>
      <dc:date>2019-05-03T19:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: PROC GCHAR  HBAR Color based on variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/556097#M9762</link>
      <description>Are you required to use GCHART? I would highly recommend new SAS graphs use SGPLOT instead and in this case you could control the color and symbols using a data attribute map.</description>
      <pubDate>Fri, 03 May 2019 19:57:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/556097#M9762</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-03T19:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: PROC GCHAR  HBAR Color based on variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/556103#M9765</link>
      <description>&lt;P&gt;Gchart and Gplot tend to assign the first pattern or symbol statement values to the first encountered value, second and others likewise. As such unless you 1) sort the data by the variable of interest to set the order and 2) ALWAYS have the same values in the variable your request tends to be moderately awkward to accomplish at best.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Sgplot and Sgpanel procedures, as well as graph templates you create,&amp;nbsp;can use a special data set called a DATTRMAP, for discrete attribute map, to consistently display the same color/ marker/ line type/ pattern fill for a give value for a variable used as a Group variable.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 20:51:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/556103#M9765</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-03T20:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: PROC GCHAR  HBAR Color based on variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/557793#M10034</link>
      <description>&lt;P&gt;Can you please provide an example on how you would conditionally change the bar colors using&amp;nbsp;&lt;SPAN&gt;DATTRMAP?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 14:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/557793#M10034</guid>
      <dc:creator>zdeb15</dc:creator>
      <dc:date>2019-05-10T14:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: PROC GCHAR  HBAR Color based on variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/557810#M10038</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data &lt;STRONG&gt;&lt;FONT size="5" color="#FF9900"&gt;myattrmap&lt;/FONT&gt;&lt;/STRONG&gt;;
length linecolor $ 9 fillcolor $ 9;
input &lt;FONT size="5" color="#FF0000"&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/FONT&gt; $ value $ linecolor $ fillcolor $;
datalines;
&lt;FONT size="5" color="#0000FF"&gt;&lt;STRONG&gt;myid&lt;/STRONG&gt;&lt;/FONT&gt;  F pink pink
&lt;STRONG&gt;&lt;FONT size="5" color="#0000FF"&gt;myid&lt;/FONT&gt;&lt;/STRONG&gt;  M lightblue lightblue
;
run;

proc sgplot data=sashelp.class dattrmap=&lt;FONT size="5" color="#FF6600"&gt;&lt;STRONG&gt;myattrmap&lt;/STRONG&gt;&lt;/FONT&gt;;
vbar age / response=height group=sex groupdisplay=cluster attrid=&lt;FONT size="5" color="#0000FF"&gt;&lt;STRONG&gt;myid&lt;/STRONG&gt;&lt;/FONT&gt;;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's an example. You can use fill colour changes the bar color the line colour changes the outline of the bars colour.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: add source reference:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=grstatproc&amp;amp;docsetTarget=n18szqcwir8q2nn10od9hhdh2ksj.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=grstatproc&amp;amp;docsetTarget=n18szqcwir8q2nn10od9hhdh2ksj.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272807"&gt;@zdeb15&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Can you please provide an example on how you would conditionally change the bar colors using&amp;nbsp;&lt;SPAN&gt;DATTRMAP?&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 15:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/557810#M10038</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-10T15:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC GCHAR  HBAR Color based on variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/557841#M10043</link>
      <description>&lt;P&gt;I am trying something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data dattrmap; set Top7Summarized;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;value=Fall7;&lt;BR /&gt;length FILLCOLOR $8;&lt;BR /&gt;id = 'xcolor';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if FallRed=1 then FILLCOLOR= 'Red'; else FILLCOLOR='Green';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data=dattrmap; by ID; run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;TITLE &amp;amp;titlstuf "Number of Falls (Last 7 Days)";&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sgplot data=dattrmap dattrmap=dattrmap noautolegend noborder nowall ; ods graphics / noborder;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Hbar Floor/response=Fall7 attrid=xcolor dataskin=crisp fill ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This returns the graph I want but the color of the bars remain grey. Am I able to change bar colors based on an if statement? Or can I only hard set the colors?&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2019 15:41:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/557841#M10043</guid>
      <dc:creator>zdeb15</dc:creator>
      <dc:date>2019-05-10T15:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: PROC GCHAR  HBAR Color based on variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/557851#M10045</link>
      <description>Time to provide some sample data - I think the structure of your data is problematic here - and what you want as the output. You can mock it up in Excel and post here as image please.</description>
      <pubDate>Fri, 10 May 2019 15:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/557851#M10045</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-10T15:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: PROC GCHAR  HBAR Color based on variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/557854#M10046</link>
      <description>data want;&lt;BR /&gt;length Floor $10;&lt;BR /&gt;infile datalines delimiter=',';&lt;BR /&gt;input Floor $ Fall7 FallRed ;&lt;BR /&gt;datalines;&lt;BR /&gt;Floor 2,2,1&lt;BR /&gt;Floor 3,1,0,&lt;BR /&gt;Floor 4,0,0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data dattrmap; set want;&lt;BR /&gt;&lt;BR /&gt;value=Fall7;&lt;BR /&gt;length FILLCOLOR $8;&lt;BR /&gt;id = 'xcolor';&lt;BR /&gt;&lt;BR /&gt;if FallRed=1 then FILLCOLOR= 'Red'; else FILLCOLOR='Green';&lt;BR /&gt;output;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sort data=dattrmap; by ID; run;&lt;BR /&gt;&lt;BR /&gt;TITLE &amp;amp;titlstuf "Number of Falls (Last 7 Days)";&lt;BR /&gt;&lt;BR /&gt;proc sgplot data=dattrmap dattrmap=dattrmap noautolegend noborder nowall ; ods graphics / noborder;&lt;BR /&gt;Hbar Floor/response=Fall7 group= floor groupdisplay=cluster attrid=xcolor dataskin=crisp fill&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Does this help?&lt;BR /&gt;</description>
      <pubDate>Fri, 10 May 2019 16:05:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/557854#M10046</guid>
      <dc:creator>zdeb15</dc:creator>
      <dc:date>2019-05-10T16:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC GCHAR  HBAR Color based on variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/557876#M10047</link>
      <description>&lt;P&gt;What you're doing here is conditional formatting based on a a specific value of Floor it seems? You need to uniquely identify the groups somehow. This seems to work for your example data. I suspect it may not work for your real data if you've oversimplified your example data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data dattrmap; set want;

value=Floor;
length FILLCOLOR $8;
id = 'floor';

if Floor='Floor 2' then FILLCOLOR= 'Red'; else FILLCOLOR='Green';
output;

keep id value fillcolor;
run;

proc sort data=dattrmap; by ID; run;

TITLE &amp;amp;titlstuf "Number of Falls (Last 7 Days)";

proc sgplot data=want dattrmap=dattrmap noautolegend noborder nowall ; ods graphics / noborder;
Hbar Floor/response=Fall7 group= floor groupdisplay=cluster attrid=floor dataskin=crisp fill
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 May 2019 16:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-GCHAR-HBAR-Color-based-on-variable/m-p/557876#M10047</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-10T16:53:21Z</dc:date>
    </item>
  </channel>
</rss>

