Terminology Graph - Systolic Pressure

This code is also available in: Deutsch Español Français
Difficulty Level
Beginner
Published on :
The script begins by initializing ODS options for graphical output (output path, DPI resolution). It then defines a reusable graph template (`STATGRAPH Terminology`) via `PROC TEMPLATE`. This template includes a title, a footnote, a two-row lattice layout, an overlay graph combining a histogram and density curves (normal and kernel) with a legend, and a horizontal box plot. Finally, `PROC SGRENDER` is used to apply this template to `sashelp.heart` data, filtered for individuals with 'ageatstart' greater than 50, and to visualize the 'Systolic' variable as a dynamic variable.
Data Analysis

Type : SASHELP


The script uses the internal SASHELP.HEART dataset. A filter is applied to select records where 'ageatstart' is greater than 50.

1 Code Block
Macros / ODS
Explanation :
Initializes ODS (Output Delivery System) options for graph generation. Defines the output path (`gpath`) and image resolution (`dpi`). The default HTML destination is closed to avoid unwanted output and ensure that only graphical output is produced.
Copied!
1%let gpath='.'; /*--Put your Folder Name here--*/
2%let dpi=300;
3ods listing style=listing image_dpi=&dpi gpath=&gpath;
4ods html close;
2 Code Block
PROC TEMPLATE (STATGRAPH)
Explanation :
Defines a graph template named 'Terminology' using the SGPLOT language. This template creates a complex graph composed of a title, a footnote, a histogram, density curves (normal and kernel) with a discrete legend, and a box plot. It is designed to accept a dynamic variable `_var` which will be specified when calling the template.
Copied!
1PROC TEMPLATE;
2 define statgraph Terminology;
3 dynamic _var;
4 begingraph;
5 entrytitle 'Distribution of Systolic Blood Pressure';
6 entryfootnote halign=left 'For Age at Start > 50' / textattrs=(size=7);
7 
8 layout lattice / rowweights=(0.8 0.2) columns=1
9 columndatarange=union;
10 columnaxes;
11 columnaxis / display=(ticks tickvalues line);
12 endcolumnaxes;
13 
14 layout overlay;
15 histogram _var / binaxis=false;
16 densityplot _var / name='n' legendlabel='Normal';
17 densityplot _var / kernel() lineattrs=graphfit2(pattern=solid)
18 name='k' legendlabel='Kernel';
19 discretelegend 'n' 'k' / location=inside halign=right valign=top across=1
20 itemsize=(linelength=20);
21 endlayout;
22 
23 layout overlay;
24 boxplot y=_var / orient=horizontal boxwidth=0.8;
25 endlayout;
26 
27 endlayout;
28 
29 endgraph;
30 END;
31RUN;
3 Code Block
PROC SGRENDER
Explanation :
Configures ODS graphical options for output (no border, 4-inch width, image name). Calls the previously defined 'Terminology' STATGRAPH template, providing it with `sashelp.heart` data (filtered for 'ageatstart > 50') and assigning the 'Systolic' variable to the template's dynamic `_var` variable. This generates and exports the final graph.
Copied!
1ods graphics / reset noborder width=4in imagename='6_3_Terminology';
2PROC SGRENDER DATA=sashelp.heart(where=(ageatstart > 50)) template=Terminology;
3dynamic _var='Systolic';
4RUN;
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.

Related Documentation

Aucune documentation spécifique pour cette catégorie.