Published on :
Reporting SASHELP

Creating a Composite Graph Panel with GTL

This code is also available in: Deutsch Español Français
Awaiting validation
This script demonstrates advanced use of the TEMPLATE procedure and GTL (Graph Template Language) to define a custom layout (lattice layout). It visualizes data from the SASHELP.HEART cardiac study by comparing characteristics based on sex and cause of death. The panel includes a scatter plot (Cholesterol vs. Systolic), a bar chart of mean weights, and box plots of diastolic pressure.
Data Analysis

Type : SASHELP


Data comes from the standard SASHELP.HEART table. A DATA step is used to recode some values of the 'deathcause' variable (CVD, CHD) for better graphical readability.

1 Code Block
INITIALIZATION
Explanation :
Configuration of the ODS (Output Delivery System) output environment, defining the output path and image resolution (DPI).
Copied!
1%let gpath='.'; /*--Put your Folder Name here--*/
2%let dpi=300;
3odds listing style=listing image_dpi=&dpi gpath=&gpath;
4odds html close;
2 Code Block
PROC TEMPLATE
Explanation :
Definition of the graphic template 'Fig_7_0_Panel' using GTL. The 'lattice' layout divides the space into two columns (60%/40% weighting). The first column contains a scatterplot. The second column is subdivided into two rows containing a barchart and a boxplot.
Copied!
1PROC TEMPLATE;
2 define statgraph Fig_7_0_Panel;
3 begingraph;
4 entrytitle "Characteristics of Subjects in the Study";
5 layout lattice / columns=2 columnweights=(0.6 0.4) columngutter=10px;
6 sidebar / spacefill=false;
7 discretelegend 'a';
8 endsidebar;
9 layout overlay;
10 scatterplot x=cholesterol y=systolic / group=sex name='a'
11 markerattrs=(symbol=circlefilled) datatransparency=0.5;
12 endlayout;
13 layout lattice / rows=2 columndatarange=union;
14 columnaxes;
15 columnaxis / discreteopts=(tickvaluefitpolicy=stagger) tickvalueattrs=(size=6);
16 endcolumnaxes;
17 layout overlay / yaxisopts=(labelattrs=(size=8) tickvalueattrs=(size=6)
18 label='Weight(mean)' offsetmin=0)
19 xaxisopts=(labelattrs=(size=8) tickvalueattrs=(size=6));
20 barchart x=deathcause y=weight / group=sex groupdisplay=cluster stat=mean
21 baselineattrs=(thickness=0) fillattrs=(transparency=0.2) outlineattrs=(color=black);
22 endlayout;
23 layout overlay / yaxisopts=(labelattrs=(size=8) tickvalueattrs=(size=6))
24 xaxisopts=(labelattrs=(size=8) tickvalueattrs=(size=6));
25 boxplot y=diastolic x=deathcause / group=sex groupdisplay=cluster
26 fillattrs=(transparency=0.2) meanattrs=(size=5 color=black) outlineattrs=(color=black);
27 endlayout;
28 endlayout;
29 endlayout;
30 endgraph;
31 END;
32RUN;
3 Code Block
DATA STEP Data
Explanation :
Data preparation: reading SASHELP.HEART (with variable selection via KEEP) and recoding long character strings in the 'deathcause' variable to simplify display on the graph axes.
Copied!
1DATA heart;
2 SET sashelp.heart(keep=Cholesterol Systolic Diastolic Deathcause Sex Weight);
3 IF deathcause="Cerebral Vascular Disease" THEN deathcause="CVD";
4 ELSE IF deathcause="Coronary Heart Disease" THEN deathcause="CHD";
5 ELSE deathcause=deathcause;
6RUN;
4 Code Block
PROC SGRENDER
Explanation :
Final graph generation. ODS Graphics is activated with specific dimensions, then PROC SGRENDER is called to apply the previously defined template ('Fig_7_0_Panel') to the prepared data ('heart').
Copied!
1ods listing;
2ods graphics / reset width=6in height=2.4in imagename="7_0_Panel_V93";
3PROC SGRENDER DATA=heart template=Fig_7_0_Panel;
4RUN;
5 
6title;
7footnote;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.