Hi,
I made a stacked bar chart using sgplot using the code below:
/*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.;
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).
Thank you!