In my VBAR chart I want to shade AGE=16 with a gray background. I have that working (AGE2=16) but I'm not able to figure out how to get the other block, (AGE2=. everything else) to have white background. I don't understand how to use ATTR parameters to get what I need.
data class;
set sashelp.class;
if age eq 16 then age2=age;
else age2=.;
run;
proc sort;
by age sex;
run;
proc print;
run;
ods output sgplot=sglot;
proc sgplot data=class;
styleattrs DATACOLORS=(Black Gray);
vbarbasic age / nooutline
group = sex
groupdisplay=cluster
response=Weight
stat=mean
;
block x=age block=age2 / novalues transparency=.9;
run;
In the figure I have AGE=16 shaded as I would like. I need to understand how get BLOCK AGE2=. not shaded or shaded with color=white.
Something like this should work for you:
proc sgplot data=class;
styleattrs DATACOLORS=(Black Gray);
vbarbasic age / nooutline
group = sex
groupdisplay=cluster
response=Weight
stat=mean
;
block x=age block=age2 / novalues fillattrs=(color=white)
altfillattrs=(color=cxAAAAAA) transparency=0.9 filltype=alternate;
run;
Something like this should work for you:
proc sgplot data=class;
styleattrs DATACOLORS=(Black Gray);
vbarbasic age / nooutline
group = sex
groupdisplay=cluster
response=Weight
stat=mean
;
block x=age block=age2 / novalues fillattrs=(color=white)
altfillattrs=(color=cxAAAAAA) transparency=0.9 filltype=alternate;
run;
Thanks @DanH_sas I will try this. I found another way using X=AGE2 BLOCK=AGE2
block x=age2 block=age2 /
FILLATTRS=(color='GRAY')
novalues transparency=.8;
Actually, your way is better, as "age2" contains only the one bar you want to highlight. That way, you don't have to deal with any interactions with the other bars.
I am not sure what you want for output. Can you point to an example somewhat like what you want?
I suspect part of the issues may be the MISSING values for age2.
See if this with light green/ red backgrounds looks somewhat like you expect. If the "green" should be white then change it.
I'm not really sure what color you want for the age 16, but I would specify that instead where I have red.
You might also want the BLOCK before the VBARBASIC to avoid shading the bar colors.
data class; set sashelp.class; if age eq 16 then age2='block2'; else age2='block1'; run; proc sort; by age sex; run; proc print; run; ods output sgplot=sglot; proc sgplot data=class; styleattrs DATACOLORS=(Black Gray); block x=age block=age2 / filltype=alternate fillattrs=(color=green) altfillattrs=(color=red) novalues transparency=.9; vbarbasic age / nooutline group = sex groupdisplay=cluster response=Weight stat=mean ; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.