Hi @MFraga
You can use the code below as a starter for your graph. It uses an attribute map to change the color for the bars and the text within the bars. An XAXISTABLE statement is used with an attribute map to change the font weight for the World region.
I hope this helps.
Regards,
Marcia
/* ========================================================= */
/* Input data */
/* ========================================================= */
data have;
input region_code region $ 3-16 income year;
/* create duplicate region variable for axistable attribute map */
regionlbl=region;
/* define the location for the bar label */
label_loc=0;
datalines;
0 North America 50432 2024
1 South America 43713 2024
2 Asia 56297 2024
3 Europe 49000 2024
4 Africa 48383 2024
5 Oceania 38765 2024
99 World 47765 2024
;
run;
/* ========================================================= */
/* Sort regions according to the order of interest */
/* (here: descending income) */
/* ========================================================= */
proc sort data=have out=ord;
by descending income;
run;
proc format;
value $region_fmt
'North America' = 'North#America'
'South America' = 'South#America'
'Asia' = 'Asia'
'Europe' = 'Europe'
'Africa' = 'Africa'
'Oceania' = 'Oceania'
'World' = 'World';
run;
/* attribute map for bar chart and text plot */
data attrmap;
set ord;
length textcolor $9 fillcolor textweight $6;
id='code_text';
value=region;
if region_code=99 then do;
fillcolor='orange';
textcolor='blue';
end;
else do;
fillcolor='green';
textcolor='black';
end;
textfamily = "Arial Symbol";
textsize = 10;
textstyle = "Normal";
textweight = "Bold";
run;
/* attribute map for axis table */
data attrmap2;
id="region";
length textcolor $9 textweight $6;
set ord;
value=region;
textcolor='black';
if region_code=99 then textweight="bold";
else textweight='normal';
run;
data allattr;
set attrmap attrmap2;
run;
ods graphics / attrpriority=none;
proc sgplot data=ord dattrmap=allattr noautolegend noborder;
vbarparm
category = region
response = income
/
group = region
attrid = code_text
barwidth = 0.8
baselineattrs = (thickness = 0pt)
dataskin = none
nooutline;
/* Display income values as vertical text above bars */
text x=region y=label_loc text=income / group=region
attrid = code_text
position = right
textattrs=(size=10)
rotate = 90;
xaxistable regionlbl / textgroup=regionlbl textgroupid=region nolabel valueattrs=(size=10);
/* X-axis configuration */
xaxis discreteorder=data
display=(nolabel novalues)
tickstyle = inbetween
fitpolicy = split
splitchar = '#';
/* Y-axis configuration */
yaxis
values = (30000 to 60000 by 2000)
display = (nolabel noline)
valueattrs = (family = 'Arial Symbol')
valueshint
valuesformat = $region_axis_fmt.
offsetmin=0;
run;
Hi @MFraga
You can use the code below as a starter for your graph. It uses an attribute map to change the color for the bars and the text within the bars. An XAXISTABLE statement is used with an attribute map to change the font weight for the World region.
I hope this helps.
Regards,
Marcia
/* ========================================================= */
/* Input data */
/* ========================================================= */
data have;
input region_code region $ 3-16 income year;
/* create duplicate region variable for axistable attribute map */
regionlbl=region;
/* define the location for the bar label */
label_loc=0;
datalines;
0 North America 50432 2024
1 South America 43713 2024
2 Asia 56297 2024
3 Europe 49000 2024
4 Africa 48383 2024
5 Oceania 38765 2024
99 World 47765 2024
;
run;
/* ========================================================= */
/* Sort regions according to the order of interest */
/* (here: descending income) */
/* ========================================================= */
proc sort data=have out=ord;
by descending income;
run;
proc format;
value $region_fmt
'North America' = 'North#America'
'South America' = 'South#America'
'Asia' = 'Asia'
'Europe' = 'Europe'
'Africa' = 'Africa'
'Oceania' = 'Oceania'
'World' = 'World';
run;
/* attribute map for bar chart and text plot */
data attrmap;
set ord;
length textcolor $9 fillcolor textweight $6;
id='code_text';
value=region;
if region_code=99 then do;
fillcolor='orange';
textcolor='blue';
end;
else do;
fillcolor='green';
textcolor='black';
end;
textfamily = "Arial Symbol";
textsize = 10;
textstyle = "Normal";
textweight = "Bold";
run;
/* attribute map for axis table */
data attrmap2;
id="region";
length textcolor $9 textweight $6;
set ord;
value=region;
textcolor='black';
if region_code=99 then textweight="bold";
else textweight='normal';
run;
data allattr;
set attrmap attrmap2;
run;
ods graphics / attrpriority=none;
proc sgplot data=ord dattrmap=allattr noautolegend noborder;
vbarparm
category = region
response = income
/
group = region
attrid = code_text
barwidth = 0.8
baselineattrs = (thickness = 0pt)
dataskin = none
nooutline;
/* Display income values as vertical text above bars */
text x=region y=label_loc text=income / group=region
attrid = code_text
position = right
textattrs=(size=10)
rotate = 90;
xaxistable regionlbl / textgroup=regionlbl textgroupid=region nolabel valueattrs=(size=10);
/* X-axis configuration */
xaxis discreteorder=data
display=(nolabel novalues)
tickstyle = inbetween
fitpolicy = split
splitchar = '#';
/* Y-axis configuration */
yaxis
values = (30000 to 60000 by 2000)
display = (nolabel noline)
valueattrs = (family = 'Arial Symbol')
valueshint
valuesformat = $region_axis_fmt.
offsetmin=0;
run;
Dive into keynotes, announcements and breakthroughs on demand.
Explore Now →Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.