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!
%let gpath='.'; /*--Put your Folder Name here--*/
%let dpi=300;
odds listing style=listing image_dpi=&dpi gpath=&gpath;
odds html close;
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.
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!
data heart;
set sashelp.heart(keep=Cholesterol Systolic Diastolic Deathcause Sex Weight);
if deathcause="Cerebral Vascular Disease" then deathcause="CVD";
else if deathcause="Coronary Heart Disease" then deathcause="CHD";
else deathcause=deathcause;
run;
1
DATA heart;
2
SET sashelp.heart(keep=Cholesterol Systolic Diastolic Deathcause Sex Weight);
3
IF deathcause="Cerebral Vascular Disease"THEN deathcause="CVD";
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').
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.