<?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 how to change legend content for a stacked bar chart (sgplot) in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/how-to-change-legend-content-for-a-stacked-bar-chart-sgplot/m-p/778075#M31485</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I made a stacked bar chart using sgplot using the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*stacked by date*/
data stacked_v2;
set loc.loc_inclus_vo;
if loc1=1 then level1=1; else level1=0;
if loc1=2 then level2=1; else level2=0;
if loc1=3 then level3=1; else level3=0;
if loc1=4 then level4=1; else level4=0;
keep patient_site_uid episode_start_time level1 level2 level3 level4;



/*stacked bar chart*/
proc sort data=stacked_v2;
by patient_site_uid;

proc transpose data=stacked_v2
out=long(where=(col1 ne 0));
by patient_site_uid episode_start_time;
var level:;
run;

data level_data;
set long;
level = substr(compress(reverse(_name_)), 1, 1);
run;

/*stacked monthly bar chart*/
proc freq data=level_data;
table episode_start_time * level / nopercent norow nocol;
run;

proc sort data=level_data;
by episode_start_time level;

data legend_order;
retain Id 'Origin' Show 'Attrmap';
length Value $10 FillStyleElement $15;
input value $ FillStyleElement $;
datalines;
1 graphdata1
2 graphdata2
3 graphdata3
4 graphdata4
;
run;

proc sgplot data=level_data dattrmap=legend_order;
vbar episode_start_time/ group=level datalabel seglabel
attrid=Origin;
format episode_start_time MONYY7.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I change the legend so that instead of having levels= 1,2,3 or 4 for each stack in the legend, I can give names to each level (eg. level=1 become "nurse", level=2 become "doctor")? I've tried changing it at the data stacked_v2 step, but it doesn't work with further steps (since changing the numeric level to character doesn't work with further steps).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Nov 2021 01:56:50 GMT</pubDate>
    <dc:creator>sasthalie</dc:creator>
    <dc:date>2021-11-03T01:56:50Z</dc:date>
    <item>
      <title>how to change legend content for a stacked bar chart (sgplot)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-change-legend-content-for-a-stacked-bar-chart-sgplot/m-p/778075#M31485</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I made a stacked bar chart using sgplot using the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*stacked by date*/
data stacked_v2;
set loc.loc_inclus_vo;
if loc1=1 then level1=1; else level1=0;
if loc1=2 then level2=1; else level2=0;
if loc1=3 then level3=1; else level3=0;
if loc1=4 then level4=1; else level4=0;
keep patient_site_uid episode_start_time level1 level2 level3 level4;



/*stacked bar chart*/
proc sort data=stacked_v2;
by patient_site_uid;

proc transpose data=stacked_v2
out=long(where=(col1 ne 0));
by patient_site_uid episode_start_time;
var level:;
run;

data level_data;
set long;
level = substr(compress(reverse(_name_)), 1, 1);
run;

/*stacked monthly bar chart*/
proc freq data=level_data;
table episode_start_time * level / nopercent norow nocol;
run;

proc sort data=level_data;
by episode_start_time level;

data legend_order;
retain Id 'Origin' Show 'Attrmap';
length Value $10 FillStyleElement $15;
input value $ FillStyleElement $;
datalines;
1 graphdata1
2 graphdata2
3 graphdata3
4 graphdata4
;
run;

proc sgplot data=level_data dattrmap=legend_order;
vbar episode_start_time/ group=level datalabel seglabel
attrid=Origin;
format episode_start_time MONYY7.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I change the legend so that instead of having levels= 1,2,3 or 4 for each stack in the legend, I can give names to each level (eg. level=1 become "nurse", level=2 become "doctor")? I've tried changing it at the data stacked_v2 step, but it doesn't work with further steps (since changing the numeric level to character doesn't work with further steps).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 01:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-change-legend-content-for-a-stacked-bar-chart-sgplot/m-p/778075#M31485</guid>
      <dc:creator>sasthalie</dc:creator>
      <dc:date>2021-11-03T01:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to change legend content for a stacked bar chart (sgplot)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-change-legend-content-for-a-stacked-bar-chart-sgplot/m-p/778138#M31491</link>
      <description>&lt;P&gt;Let us know if this helps, or not:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-change-legend-label-for-stacked-bar-chart-in-proc-sgplot/td-p/613174" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-change-legend-label-for-stacked-bar-chart-in-proc-sgplot/td-p/613174&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 11:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-change-legend-content-for-a-stacked-bar-chart-sgplot/m-p/778138#M31491</guid>
      <dc:creator>SAS_Cares</dc:creator>
      <dc:date>2021-11-03T11:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to change legend content for a stacked bar chart (sgplot)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-change-legend-content-for-a-stacked-bar-chart-sgplot/m-p/778180#M31498</link>
      <description>&lt;P&gt;This solves things. Thank you so much!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 13:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-change-legend-content-for-a-stacked-bar-chart-sgplot/m-p/778180#M31498</guid>
      <dc:creator>sasthalie</dc:creator>
      <dc:date>2021-11-03T13:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to change legend content for a stacked bar chart (sgplot)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-change-legend-content-for-a-stacked-bar-chart-sgplot/m-p/778226#M31504</link>
      <description>&lt;P&gt;Fantastic, glad that helped!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 15:01:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-change-legend-content-for-a-stacked-bar-chart-sgplot/m-p/778226#M31504</guid>
      <dc:creator>SAS_Cares</dc:creator>
      <dc:date>2021-11-03T15:01:13Z</dc:date>
    </item>
  </channel>
</rss>

