I think the easiest way for this case here is to use a range attributes map. The key is mapping the region/year combinations into a single numeric value that you can use in the attributes map.
data have;
input code region $ 3-16 growth_rate year;
datalines;
0 North America -5.92 2020
0 North America -2.18 2021
0 North America -7.47 2022
0 North America -2.17 2023
0 North America -9.64 2024
1 South America 0.36 2020
1 South America 2.69 2021
1 South America -8.13 2022
1 South America 1.22 2023
1 South America -1.34 2024
2 Asia -1.53 2020
2 Asia 2.18 2021
2 Asia 5.64 2022
2 Asia 6.80 2023
2 Asia 8.70 2024
3 Europe -9.68 2020
3 Europe 3.91 2021
3 Europe 5.48 2022
3 Europe 3.52 2023
3 Europe 3.69 2024
4 Africa 3.29 2020
4 Africa 7.97 2021
4 Africa 2.48 2022
4 Africa 7.36 2023
4 Africa 1.31 2024
5 Oceania 8.00 2020
5 Oceania -6.05 2021
5 Oceania 6.91 2022
5 Oceania -1.09 2023
5 Oceania -7.46 2024
;
run;
proc sort data=have(where=(year=2024)) out=temp;
by descending growth_rate ;
run;
data fmt;
set temp(rename=(region=start));
retain fmtname 'fmt' type 'c';
length label $ 80;
label=repeat(' ',_n_)||strip(start);
keep fmtname type start label;
run;
proc format cntlin=fmt;
run;
data have2;
set have;
_region=put(region,$fmt32.);
if region="North America" then call symput('NorthAmerica',_region);
run;
data have3;
set have2;
if region="North America" then do;
if year=2020 then color=1;
else if year=2021 then color=2;
else if year=2022 then color=3;
else if year=2023 then color=4;
else if year=2024 then color=5;
end;
if region NE "North America" then do;
if year=2020 then color=6;
else if year=2021 then color=7;
else if year=2022 then color=8;
else if year=2023 then color=9;
else if year=2024 then color=10;
end;
run;
data attrmap;
retain ID "barcolors" altcolor "black";
input min $ max $ color $;
datalines;
1 1 cxf7ebde
2 2 cxefdbc6
3 3 cxe1ca9e
4 4 cxd6ae6b
5 5 cxb4771f
6 6 cxdeebf7
7 7 cxc6dbef
8 8 cx9ecae1
9 9 cx6baed6
10 10 cx1f77b4
;
run;
data sganno;
%sganno
%SGTEXT(LABEL="North America",TEXTWEIGHT="BOLD",TEXTCOLOR="RED",TEXTSIZE=10, FILLCOLOR="white",FILLTRANSPARENCY=0,WIDTH=40,Y1SPACE="DATAVALUE",X1SPACE="LAYOUTPERCENT",YC1="&NorthAmerica.",X1=6 )
run;
proc sgplot data=have3 sganno=sganno rattrmap=attrmap noautolegend;
title "Growth rate";
hbar _region / response=growth_rate group=year colorresponse=color rattrid=barcolors
groupdisplay=cluster
clusterwidth=0.9
datalabel DATALABELFITPOLICY=NONE
datalabelattrs=(size=8pt)
barwidth=1 nooutline
transparency=0 dataskin=none;
xaxis display=(nolabel) min=-12 max=12;
yaxis display=(nolabel) colorbands=even ;
run;
... View more