Does anyone know the code to do a chart like this, in SAS 9.4? Where the survey questions are on the y axis and the survey scores are on the x-axis, divided up in the legend between pre and post, plus standard deviations.
See attached photo example
SGPLOT can do this, but the bar segments are side by side (GROUPDISPLAY=CLUSTER)
If you want the stacked bar then you need to calculate the values up front and use VBARPARM together with the HIGHLOW plot statements.
Here is an example ussing SASHELP.CARS
/*
* generate test data
*/
data cars;
set sashelp.cars;
where
origin in ("Asia", "USA")
and not (type = "Hybrid")
;
/*
* choose which var to use
*/
value = horsepower;
format value comma12.;
run;
/*
* what you get for free
*/
ods graphics / width=1200 height=900;
proc sgplot data=cars;
vbar type /
group=origin
response=value
stat=mean
limits=both
limitstat=stddev
groupdisplay=cluster
seglabel
;
run;
/*
* calculate mean and std
*/
proc sql;
create table cars_limits as
select
type
, origin
, mean(value) as mean_value format=comma12.
, std(value) as std_value format=comma12.
from
cars
group by
type
, origin
order by
type
, origin
;
quit;
/*
* compute values used with highlow stmt
*/
data cars_limits2;
set cars_limits;
by type;
mean_value2 = lag1(mean_value);
if origin = "Asia" then do;
a_ll = mean_value - (1 * std_value);
a_ul = mean_value + (1 * std_value);
end;
if origin = "USA" then do;
b_ll = mean_value2 + ( mean_value - (1 * std_value) );
b_ul = mean_value2 + ( mean_value + (1 * std_value) );
end;
run;
/*
* create graph
*/
proc sgplot data=cars_limits2;
vbarparm category=type response=mean_value / group=origin groupdisplay=stack seglabel;
highlow x=type low=a_ll high=a_ul / group=origin lowcap=serif highcap=serif lineattrs=(color=cx000000);
highlow x=type low=b_ll high=b_ul / group=origin lowcap=serif highcap=serif lineattrs=(color=cx000000);
run;
Sorry I missed the point that this is all to be in Visual Analytics.
Have a look here https://communities.sas.com/t5/SAS-Visual-Analytics/Plot-of-Standard-Deviation-in-SAS-VA-Report-Desi... it is not a stacked bar chart, but might give you starting point.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.