<?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: Proc GCHART display variable in the bar in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/914716#M360448</link>
    <description>Please show a sample of your data format and desired graph. &lt;BR /&gt;&lt;BR /&gt;GCHART still has some uses, but typically the recommendation is to use SGPLOT instead.&lt;BR /&gt;&lt;BR /&gt;An HBAR statement + a TEXT statement may be what you need in SGPLOT.</description>
    <pubDate>Tue, 06 Feb 2024 16:06:48 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2024-02-06T16:06:48Z</dc:date>
    <item>
      <title>Proc GCHART display variable in the bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/914690#M360435</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have my dataset PYR_AGE_POP_4 (in an excel file joined) and i want to have the variable poids displayed inside each bar but i can't do it.&lt;/P&gt;&lt;P&gt;Do you have an idea please ?&lt;/P&gt;&lt;P&gt;There is below my currently code:&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc format;&lt;BR /&gt;picture posval low-high='000,009';&lt;BR /&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;legend label=(" ");&lt;/DIV&gt;&lt;DIV&gt;AXIS1&amp;nbsp; LABEL=none MAJOR=none MINOR=none STYLE=0;&lt;/DIV&gt;&lt;DIV&gt;axis2&amp;nbsp; label=none&amp;nbsp; order=('60 ans et plus' '51 - 60 ans' '41 - 50 ans' '31 - 40 ans' '21 - 30 ans' '0 - 20 ans');&lt;/DIV&gt;&lt;DIV&gt;pattern1 value=solid color="&amp;amp;couleur_1";&lt;/DIV&gt;&lt;DIV&gt;pattern2 value=solid color="&amp;amp;couleur_2";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;PROC GCHART DATA = PYR_AGE_POP_4 ;&lt;/DIV&gt;&lt;DIV&gt;format pop posval.;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; HBAR DRS_TRANCHE_AGE / DISCRETE NOSTATS SUMVAR = pop&amp;nbsp; TYPE = SUM SUBGROUP = DRS_SEXE1 GSPACE=0 space=0&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;legend=legend&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;RAXIS=axis1&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MAXIS=axis2 autoref&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;RUN ; QUIT ;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have a solution please ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 14:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/914690#M360435</guid>
      <dc:creator>Mathassens</dc:creator>
      <dc:date>2024-02-06T14:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Proc GCHART display variable in the bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/914716#M360448</link>
      <description>Please show a sample of your data format and desired graph. &lt;BR /&gt;&lt;BR /&gt;GCHART still has some uses, but typically the recommendation is to use SGPLOT instead.&lt;BR /&gt;&lt;BR /&gt;An HBAR statement + a TEXT statement may be what you need in SGPLOT.</description>
      <pubDate>Tue, 06 Feb 2024 16:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/914716#M360448</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-02-06T16:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: Proc GCHART display variable in the bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/914875#M360526</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks you Reeza for your answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am now trying to use the sgplot procedure to get what i want.&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;DIV&gt;PROC SGPLOT DATA=PYR_AGE_POP_4 noborder nowall noautolegend dattrmap=essai1;&lt;/DIV&gt;&lt;DIV&gt;format pop posval. poids percentn8.;&lt;/DIV&gt;&lt;DIV&gt;HBARparm category=DRS_TRANCHE_AGE&amp;nbsp; response=pop / barwidth=0.4&amp;nbsp; group=DRS_SEXE1&amp;nbsp; datalabel GROUPDISPLAY=CLUSTER COLORMODEL=("&amp;amp;couleur_1." "&amp;amp;couleur_2.") colorresponse=pop&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;fillattrs=(color="&amp;amp;couleur_2.") legendlabel="" name='hbar';&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; text text=poids x=position_x y=DRS_TRANCHE_AGE&amp;nbsp; &amp;nbsp;/&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;strip position=center /*backfill fillattrs=(color=grey&amp;nbsp; transparency=.3)*/&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;textattrs=(size=8 color=grey weight=bold family=arial ) GROUPDISPLAY=CLUSTER/*legendlabel="poids"*/ legendlabel="poids" splitpolicy=splitalways;&lt;/DIV&gt;&lt;DIV&gt;XAXIS label="Effectif par sexe" ;&lt;/DIV&gt;&lt;DIV&gt;YAXIS label="" /*offsetmin=0*/;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; KEYLEGEND 'hbar'/ location=outside POSITION=bottom NOBORDER ;&lt;/DIV&gt;&lt;DIV&gt;RUN ;&lt;/DIV&gt;&lt;P&gt;But i have somme issues:&lt;/P&gt;&lt;P&gt;1) the color of my legend aren't the same than in my graphic. (graphic_obtained in the attached files)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="graphic obtained" style="width: 841px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93336iCA3C0E3DF87928BE/image-size/large?v=v2&amp;amp;px=999" role="button" title="graphic_obtained.png" alt="graphic obtained" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;graphic obtained&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;2) Ideally, i want to have&amp;nbsp; the graphic like graphic_wanted in the attached files&amp;nbsp; &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;&lt;P&gt;Thanks you for your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="graphic wanted" style="width: 580px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93334i5D295906B67429B3/image-size/large?v=v2&amp;amp;px=999" role="button" title="graphic_wanted.png" alt="graphic wanted" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;graphic wanted&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 15:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/914875#M360526</guid>
      <dc:creator>Mathassens</dc:creator>
      <dc:date>2024-02-07T15:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc GCHART display variable in the bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/914876#M360527</link>
      <description>&lt;P&gt;Here are my data &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 15:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/914876#M360527</guid>
      <dc:creator>Mathassens</dc:creator>
      <dc:date>2024-02-07T15:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc GCHART display variable in the bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/914877#M360528</link>
      <description>&lt;P&gt;Check out this post, which is far beyond what you want (an animated population pyramid, not static) but it gives you the code and example you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/graphicallyspeaking/2021/06/02/improving-a-population-pyramid-animation-sweden-1860-2020/" target="_blank"&gt;https://blogs.sas.com/content/graphicallyspeaking/2021/06/02/improving-a-population-pyramid-animation-sweden-1860-2020/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 15:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/914877#M360528</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-02-07T15:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc GCHART display variable in the bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/915117#M360603</link>
      <description>&lt;P&gt;Thanks you Reeza&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have now the following code and it's really&amp;nbsp; close of my aim, but i don't understand why the squares in my legend are not in the same colors than in my bars.&lt;/P&gt;&lt;P&gt;In the legend, the suare are not filled with the colours of my bars &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you help me please ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;PROC SGPLOT DATA=PYR_AGE_POP_4 noborder nowall noautolegend dattrmap=essai1;&lt;/DIV&gt;&lt;DIV&gt;format pop posval. poids percentn8.;&lt;/DIV&gt;&lt;DIV&gt;HBARparm category=DRS_TRANCHE_AGE&amp;nbsp; response=pop /&amp;nbsp; group=DRS_SEXE1&amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;datalabel GROUPDISPLAY=stack COLORMODEL=("&amp;amp;couleur_1." "&amp;amp;couleur_2.") colorresponse=pop name='hbar';&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; text text=poids x=position_x y=DRS_TRANCHE_AGE&amp;nbsp; &amp;nbsp;/&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;strip position=center&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;textattrs=(size=8 color=white weight=bold family=arial ) legendlabel="poids" splitpolicy=splitalways;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; XAXIS display=(nolabel);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; YAXIS display=(nolabel noline noticks) ;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; KEYLEGEND 'hbar'/ location=outside POSITION=bottom NOBORDER ;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;RUN ;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 17:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/915117#M360603</guid>
      <dc:creator>Mathassens</dc:creator>
      <dc:date>2024-02-08T17:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc GCHART display variable in the bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/915127#M360604</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/463540"&gt;@Mathassens&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/463540"&gt;@Mathassens&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;... i don't understand why the squares in my legend are not in the same colors than in my bars.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I think this is because you are using the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n0a5svhjs7b505n1vlk4kuth2x3q.htm#p0oottiwct880xn17bxx29idalzbd" target="_blank" rel="noopener"&gt;COLORRESPONSE= option&lt;/A&gt;, which corresponds to a &lt;EM&gt;gradient&lt;/EM&gt; legend (displaying a &lt;EM&gt;range&lt;/EM&gt; of colors) rather than a &lt;EM&gt;key&lt;/EM&gt; legend (with only two colors). It appears that SAS uses neutral colors in the two squares of the key legend as they can't accommodate the color &lt;EM&gt;gradient&lt;/EM&gt;. So, you may want to either omit the COLORRESPONSE= option and thus use only two colors -- then the key legend should show these two colors -- or use a&amp;nbsp;&lt;A href="http://GRADLEGEND%20statement " target="_self"&gt;GRADLEGEND statement&lt;/A&gt;&amp;nbsp;instead of the KEYLEGEND statement and maybe a trick to label the left and right half of the gradient legend with "Femmes" and "Hommes", respectively:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  label pop='Femmes                                       Hommes';
  gradlegend 'hbar' / position=bottom;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Resulting legend*&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gradlegend.png" style="width: 547px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93425iB31A7387E5BE0EDF/image-size/large?v=v2&amp;amp;px=999" role="button" title="gradlegend.png" alt="gradlegend.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;* arbitrarily using "green" and "red" for&amp;nbsp;&lt;SPAN&gt;"&amp;amp;couleur_1."&amp;nbsp; and "&amp;amp;couleur_2.", resp.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 18:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/915127#M360604</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-02-08T18:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Proc GCHART display variable in the bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/915201#M360628</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input poids	DRS_TRANCHE_AGE	&amp;amp; $40. DRS_SEXE $	pop	 DRS_SEXE1 $;
cards;
0.34	0 - 20 ans	  F	-557	Femmes
0.29	0 - 20 ans	  M	601	Hommes
0.24	21 - 30 ans  	M	490	Hommes
0.25	21 - 30 ans  	F	-402	Femmes
0.29	31 - 40 ans  	M	591	Hommes
0.28	31 - 40 ans  	F	-465	Femmes
0.13	41 - 50 ans	   M	264	Hommes
0.09	41 - 50 ans  	F	-154	Femmes
0.03	51 - 60 ans	   F	-52	Femmes
0.05	51 - 60 ans	   M	104	Hommes
0.01	60 ans et plus  	 F	-10	Femmes
0.01	60 ans et plus	  M	15	Hommes
;

proc format;
picture fmt
low-0='00000'
;
run;
proc sort data=have out=have2 ;
by DRS_SEXE1 pop;
run;
data have2;
 set have;
 if poids&amp;gt;=0.05 then x2=pop/2;
  else x3=pop+ifn(pop&amp;gt;0,50,-50);
run;
proc sgplot data=have2;
styleattrs datacolors=(MediumVioletRed navy);
hbarparm category=DRS_TRANCHE_AGE response=pop/group=DRS_SEXE1 nooutline name='x';
scatter x=x2 y=DRS_TRANCHE_AGE/markerchar=poids labelstrip markercharattrs=(color=white size=12);
scatter x=x3 y=DRS_TRANCHE_AGE/markerchar=poids labelstrip markercharattrs=(color=black size=12);

yaxis reverse label=' ';
xaxis values=(-700 to 700 by 100);
keylegend 'x'/title='';
format pop fmt. poids percent8.0;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1707466427075.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93447i553349EC2A7D4CE9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1707466427075.png" alt="Ksharp_0-1707466427075.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 08:26:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/915201#M360628</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-02-09T08:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc GCHART display variable in the bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/915246#M360642</link>
      <description>Thanks you Ksharp and FreelanceReinh.&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Feb 2024 14:32:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-GCHART-display-variable-in-the-bar/m-p/915246#M360642</guid>
      <dc:creator>Mathassens</dc:creator>
      <dc:date>2024-02-09T14:32:17Z</dc:date>
    </item>
  </channel>
</rss>

