Sample 69814: A probability distribution plot that is created with the Graph Template Language, GTL, and PROC SGRENDER
This SAS Note provides sample code for a probability distribution plot that is created with the Graph Template Language, GTL, and the SGRENDER procedure.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Sample code for a probability distribution plot that is created with the Graph Template Language, GTL, and PROC SGRENDER.
/*-------- Preparing Data For Bean Plot ----------*/
data k1;
seed = 1283470;
do i1 = 1 to 1000;
z1 = rannor(seed);
z2 = rannor(seed);
z3 = rannor(seed);
x1 = 3*z1 + z2;
y1 = 3*z1 + z3;
output;
end;
drop seed;
run;
proc kde data=k1;
univar x1 / out=o1 (drop=var rename=(density=density1 value=x1));
run;
proc means data=o1;
var x1;
output out=o1quart mean=meano1 p5=p5o1 p25=p25o1 p75=p75o1 p95=p95o1;
run;
data oquart1;
set o1quart;
low1=0;
high1=0.05;
run;
proc kde data=k1 ;
univar y1/ out=o2 (drop=var rename=(density=density2 value=y1));
run;
proc means data=o2;
var y1;
output out=o2quart mean=meano2 p5=p5o2 p25=p25o2 p75=p75o2 p95=p95o2;
run;
data oquart2;
set o2quart;
low2=-0.05;
high2=0;
run;
data k2;
seed = 1283470;
do i2 = 1 to 1000;
z12 = rannor(seed);
z22 = rannor(seed);
z32 = rannor(seed);
x2 = 1.5*z12*z12 - 2.5*z22*z22;
y2 = 5.5*z12 + z32*z32*2.5;
output;
end;
drop seed;
run;
proc kde data=k2 ;
univar x2 / out=o12 (drop=var rename=(density=density12 value=x2));
run;
proc means data=o12;
var x2;
output out=o12quart mean=meano12 p5=p5o12 p25=p25o12 p75=p75o12 p95=p95o12;
run;
data oquart12;
set o12quart;
low12=0;
high12=0.05;
run;
proc kde data=k2 ;
univar y2/ out=o22 (drop=var rename=(density=density22 value=y2));
run;
proc means data=o22;
var y2;
output out=o22quart mean=meano22 p5=p5o22 p25=p25o22 p75=p75o22 p95=p95o22;
run;
data oquart22;
set o22quart;
low22=-0.05;
high22=0;
run;
data k3;
seed = 1283470;
do i3 = 1 to 1000;
z13 = rannor(seed);
z23 = rannor(seed);
z33 = rannor(seed);
x3 = 3*z13*z13 + z23;
y3 = 4.5*z13 + 1.5*z33;
output;
end;
drop seed;
run;
proc kde data=k3 ;
univar x3 / out=o13 (drop=var rename=(density=density13 value=x3));
run;
proc means data=o13;
var x3;
output out=o13quart mean=meano13 p5=p5o13 p25=p25o13 p75=p75o13 p95=p95o13;
run;
data oquart13;
set o13quart;
low13=0;
high13=0.05;
run;
proc kde data=k3 ;
univar y3/ out=o23 (drop=var rename=(density=density23 value=y3));
run;
proc means data=o23;
var y3;
output out=o23quart mean=meano23 p5=p5o23 p25=p25o23 p75=p75o23 p95=p95o23;
run;
data oquart23;
set o23quart;
low23=-0.05;
high23=0;
run;
data dens;
merge
o1 o2 o1quart o2quart oquart1 oquart2
o12 o22 o12quart o22quart oquart12 oquart22
o13 o23 o13quart o23quart oquart13 oquart23;
run;
/*----- Template Code for Bean Plot ------*/
proc template;
define statgraph test;
begingraph;
dynamic _thick _pad _title;
entrytitle _title ;
layout lattice / columns=3 rowdatarange=unionall border=false;
rowaxes;
rowaxis/ display=(ticks tickvalues line) offsetmin=0.1;
endrowaxes;
/*--Side bar for legend--*/
sidebar / align=bottom spacefill=false;
discretelegend "band1" "band2" / border=false across=2 outerpad=(top=_pad)
valueattrs=(size=8 weight=bold);
endsidebar;
/*--Left cell--*/
layout overlay / xaxisopts=(display=none) walldisplay=none border=false;
bandplot y=x1 limitlower=0 limitupper=density1 / fillattrs=(color=lightseagreen)
datatransparency=0.4 name="band1" legendlabel="Placebo";
seriesplot y=x1 x=density1 / lineattrs=(color=lightseagreen) ;
highlowplot y=meano1 high=high1 low=low1 /
lineattrs=(color=lightseagreen pattern=dash thickness=_thick) ;
bandplot y=x1 limitlower=0 limitupper=eval(-1*density2) / name="band2"
fillattrs=(color=orange) datatransparency=0.4 legendlabel="MDA (Treatment)";
seriesplot y=x1 x=eval(-1*density2)/ lineattrs=(color=orange);
highlowplot y=meano2 high=high2 low=low2 /
lineattrs=(color=orange pattern=dash thickness=_thick);
referenceline x=0 / curvelabel="No Cue" curvelabelposition=min datatransparency=1;
endlayout;
/*--Middle cell--*/
layout overlay / xaxisopts=(display=none) walldisplay=none border=false;
bandplot y=x2 limitlower=0 limitupper=density12 /
fillattrs=(color=lightseagreen) datatransparency=0.4;
seriesplot y=x2 x=density12 / lineattrs=(color=lightseagreen);
highlowplot y=meano12 high=high12 low=low12 /
lineattrs=(color=lightseagreen pattern=dash thickness=_thick);
bandplot y=x2 limitlower=0 limitupper=eval(-1*density22) /
fillattrs=(color=orange) datatransparency=0.4;
seriesplot y=x2 x=eval(-1*density22) / lineattrs=(color=orange);
highlowplot y=meano22 high=high22 low=low22 /
lineattrs=(color=orange pattern=dash thickness=_thick);
referenceline x=0 /
curvelabel="False Cue" curvelabelposition=min datatransparency=1;
endlayout;
/*--Right cell--*/
layout overlay / xaxisopts=(display=none) walldisplay=none border=false ;
bandplot y=x3 limitlower=0 limitupper=density13 /
fillattrs=(color=lightseagreen) datatransparency=0.4;
seriesplot y=x3 x=density13 / lineattrs=(color=lightseagreen);
highlowplot y=meano13 high=high13 low=low13 /
lineattrs=(color=lightseagreen pattern=dash thickness=_thick);
bandplot y=x3 limitlower=0 limitupper=eval(-1*density23) /
fillattrs=(color=orange) datatransparency=0.4;
seriesplot y=x3 x=eval(-1*density23) / lineattrs=(color=orange);
highlowplot y=meano23 high=high23 low=low23 /
lineattrs=(color=orange pattern=dash thickness=_thick);
referenceline x=0 /
curvelabel="True Cue" curvelabelposition=min datatransparency=1;
endlayout;
endlayout;
endgraph;
end;
run;
/*----Create Graph-----*/
ods graphics / reset noscale width=8in height=4.5in imagename='BeanPlot_V94';
proc sgrender data=dens template=test;
dynamic _thick=3 _pad=10 _title="Probability Distribution Functions with Placebo and MDA";
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.

| Date Modified: | 2023-01-24 08:42:59 |
| Date Created: | 2023-01-18 15:36:09 |
Operating System and Release Information
| SAS System | Base SAS | z/OS | 9.3 TS1M2 | |
| z/OS 64-bit | 9.3 TS1M2 | |
| Microsoft® Windows® for x64 | 9.3 TS1M2 | |
| Microsoft Windows 8 Enterprise 32-bit | 9.3 TS1M2 | |
| Microsoft Windows 8 Enterprise x64 | 9.3 TS1M2 | |
| Microsoft Windows 8 Pro 32-bit | 9.3 TS1M2 | |
| Microsoft Windows 8 Pro x64 | 9.3 TS1M2 | |
| Microsoft Windows 8.1 Enterprise 32-bit | 9.3 TS1M2 | |
| Microsoft Windows 8.1 Enterprise x64 | 9.3 TS1M2 | |
| Microsoft Windows 8.1 Pro 32-bit | 9.3 TS1M2 | |
| Microsoft Windows 8.1 Pro x64 | 9.3 TS1M2 | |
| Microsoft Windows Server 2003 Datacenter Edition | 9.3 TS1M2 | |
| Microsoft Windows Server 2003 Enterprise Edition | 9.3 TS1M2 | |
| Microsoft Windows Server 2003 Standard Edition | 9.3 TS1M2 | |
| Microsoft Windows Server 2003 for x64 | 9.3 TS1M2 | |
| Microsoft Windows Server 2008 | 9.3 TS1M2 | |
| Microsoft Windows Server 2008 R2 | 9.3 TS1M2 | |
| Microsoft Windows Server 2008 for x64 | 9.3 TS1M2 | |
| Microsoft Windows Server 2012 Datacenter | 9.3 TS1M2 | |
| Microsoft Windows Server 2012 R2 Datacenter | 9.3 TS1M2 | |
| Microsoft Windows Server 2012 R2 Std | 9.3 TS1M2 | |
| Microsoft Windows Server 2012 Std | 9.3 TS1M2 | |
| Microsoft Windows XP Professional | 9.3 TS1M2 | |
| Windows 7 Enterprise 32 bit | 9.3 TS1M2 | |
| Windows 7 Enterprise x64 | 9.3 TS1M2 | |
| Windows 7 Home Premium 32 bit | 9.3 TS1M2 | |
| Windows 7 Home Premium x64 | 9.3 TS1M2 | |
| Windows 7 Professional 32 bit | 9.3 TS1M2 | |
| Windows 7 Professional x64 | 9.3 TS1M2 | |
| Windows 7 Ultimate 32 bit | 9.3 TS1M2 | |
| Windows 7 Ultimate x64 | 9.3 TS1M2 | |
| Windows Vista | 9.3 TS1M2 | |
| Windows Vista for x64 | 9.3 TS1M2 | |
| 64-bit Enabled AIX | 9.3 TS1M2 | |
| 64-bit Enabled HP-UX | 9.3 TS1M2 | |
| 64-bit Enabled Solaris | 9.3 TS1M2 | |
| HP-UX IPF | 9.3 TS1M2 | |
| Linux | 9.3 TS1M2 | |
| Linux for x64 | 9.3 TS1M2 | |
| Solaris for x64 | 9.3 TS1M2 | |