Hi ,
I would like to add text/special (Mar20*) charcters in the one of the selected bar as below.
I am using below code.
proc sgplot data=indata;
styleattrs
datafillpatterns=(r1 r3 x1 l3)
datacontrastcolors=(white black black black);
symbolchar
vbar group1 / response=COL1 group=group2 grouporder=data groupdisplay=stack fillattrs=(color="white")
outlineattrs=(color="black") fillpattern;
keylegend / position=bottom title="Bottom TItle 1";
yaxis grid label="Number of tiles";
xaxis display=(nolabel) discreteorder=data valueattrs=(size=7);
run;
Thank you,
Rajasekhar
Provide a variable with the value associated with the xaxis variable
In the VBAR statement:
Use DATALABEL= the variable name you create for that text
Use DATALABELATTRS to set attributes for the text
Use DATALABELPOS=Top to place the text at the top of the bar. You may want to control the Y Axis to allow space inside the graph for this.
ods graphics /attrpriority=none;
proc sgplot data=sashelp.heart;
styleattrs datafillpatterns=(r1 r3 x1 l3)
datacontrastcolors=(white black black black);
vbar Smoking_Status / response=weight group=bp_status grouporder=data groupdisplay=stack fillattrs=(color="white")
outlineattrs=(color="black") fillpattern;
keylegend / position=bottom title="Bottom TItle 1";
yaxis grid label="Number of tiles";
xaxis display=(nolabel) discreteorder=data valueattrs=(size=7);
refline 'Non-smoker' /axis=x transparency=1 label='Mar20*' labelpos=max labelattrs=(color=red weight=bold);
run;
Here's how to do it with annotate ...
data indata; set sashelp.stocks (where=(year(date)=2005));
run;
proc sort data=indata out=indata;
by date;
run;
proc sql noprint;
create table my_anno as
select unique date, sum(volume) as total_volume
from indata
group by date;
quit; run;
data my_anno; set my_anno;
length label $100 anchor x1space y1space textweight $50;
layer="front";
function="text"; textcolor="red"; textsize=10; textweight='bold'; anchor='bottom';
width=100; widthunit='percent';
if date='01apr2005'd then label="April Fools!";
x1space='datavalue';
y1space='datavalue';
x1=date;
y1=total_volume;
run;
proc sgplot data=indata sganno=my_anno;
vbar date / response=volume group=stock grouporder=data groupdisplay=stack;
keylegend / position=bottom title="Bottom TItle 1";
yaxis grid label="Total Volume of Stock Traded";
xaxis display=(nolabel) discreteorder=data valueattrs=(size=7);
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.