Coloring the xaxistable values using colorgroup and styleattrs.
First scenario, there is one color per group as specified in the styleattrs.
proc sql;
create table class as
select put(age,best.-l) as age
, case when age in (12,13) then '12-13'
when age in (14,15) then '14-15'
else 'Other'
end as agegrp
, mean(height) as mean_height
from sashelp.class
group by age;
quit;
proc print data=class noobs;
run;
proc sgplot data=class;
vbarbasic age / response=mean_height;
xaxistable mean_height / colorgroup = agegrp;
styleattrs datacontrastcolors=(black green red);
run;
Second scenario, only the non missing groups take a color given in styleattrs.
proc sql;
create table class as
select put(age,best.-l) as age
, case when age in (12,13) then '12-13'
when age in (14,15) then '14-15'
else ' ' /*different from scenario 1*/
end as agegrp
, mean(height) as mean_height
from sashelp.class
group by age;
quit;
proc sgplot data=class;
vbarbasic age / response=mean_height;
xaxistable mean_height / colorgroup = agegrp;
styleattrs datacontrastcolors=(/*black*/ green red);
run;
Is there an option to control the color of xaxisvlues for the missing value of the variable given in colorgroup while using styleattrs?
By default, the missing color is special, and it is retrieved from the active ODS style. However, if you use an attributes map instead of STYLEATTRS, you can control all of the colors, including "missing".
By default, the missing color is special, and it is retrieved from the active ODS style. However, if you use an attributes map instead of STYLEATTRS, you can control all of the colors, including "missing".
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.