Published on :
Reporting INTERNAL_CREATION

Measles Cases and MMR Vaccination Coverage by Year

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by defining macro variables for the output path and image resolution (DPI) for ODS. It then configures the ODS LISTING destination for graphic output. A DATA STEP is used to create a dataset named 'Measles' with embedded data (`datalines`) for the year, measles cases, and vaccination percentage. A PROC PRINT is executed to display the content of this dataset. The main part of the script uses PROC SGPLOT to visualize the data: a vertical bar chart represents vaccination coverage (Y2-axis) and a vertical line chart represents measles cases (Y-axis), allowing for easy comparison of the two metrics over time. The axes, legend, and colors are customized to improve graph readability.
Data Analysis

Type : INTERNAL_CREATION


The data used in this script is created internally via a DATALINES block within a DATA STEP. The 'Measles' dataset is generated with fixed values for the year, number of cases, and vaccination percentage.

1 Code Block
ODS Configuration
Explanation :
This block defines two macro variables: 'gpath' to specify the output directory and 'dpi' for image resolution. It closes the default ODS HTML destination and opens the ODS LISTING destination to generate output in the specified path, including images at the defined resolution.
Copied!
1%let gpath='.'; /*--Put your Folder Name here--*/
2%let dpi=300;
3ods html close;
4ods listing gpath=&gpath image_dpi=&dpi;
2 Code Block
DATA STEP Data
Explanation :
This DATA STEP creates a SAS dataset named 'Measles'. It uses the INPUT statement to define three numeric variables: 'Year', 'Cases' (measles cases), and 'Vaccine' (vaccination coverage). The data is provided directly in the script via the DATALINES statement.
Copied!
1DATA Measles;
2 INPUT Year Cases Vaccine;
3 DATALINES;
41998 100 92
51999 120 88
62000 100 88
72001 400 87
82002 500 84
92003 450 82
102004 250 80
112005 150 81
122006 700 85
132007 1000 87
142008 1300 85
152009 1100 86
162010 500 88
172011 1000 89
182012 2000 91
19;
20RUN;
3 Code Block
PROC PRINT
Explanation :
This procedure generates a simple tabular report of the previously created 'Measles' dataset, displaying all observations and variables in the ODS LISTING output window.
Copied!
1PROC PRINT;RUN;
4 Code Block
PROC SGPLOT
Explanation :
This block generates a complex graph using PROC SGPLOT. It initializes ODS GRAPHICS parameters (size, image name). The graph combines a vertical bar chart ('VBAR') for vaccination coverage (in green, on the Y2-axis) and a vertical line chart ('VLINE') for measles cases (in red, on the Y-axis). The X and Y axes are customized with specific labels, colors, and ranges, and a legend is added to identify the different metrics. The title for the graph is also defined.
Copied!
1ods graphics / reset attrpriority=color width=5in height=3in imagename='2_1_Measels';
2title 'Measles Cases and MMR Uptake by Year';
3PROC SGPLOT DATA=Measles noborder;
4 vbar year / response=vaccine nostatlabel y2axis fillattrs=(color=green) filltype=gradient
5 baselineattrs=(thickness=0) baseline=0;
6 vline year / response=cases nostatlabel lineattrs=(color=red thickness=3);
7 keylegend / location=inside position=top linelength=15;
8 yaxis offsetmin=0 display=(noline noticks) thresholdmax=0 max=2500 grid
9 label='Measels Cases in England and Wales' labelattrs=(color=red);
10 y2axis offsetmin=0 min=0 max=95 display=(noline noticks) thresholdmax=0
11 label='MMR Uptake for England' labelattrs=(color=green);
12 xaxis display=(nolabel noticks) valueattrs=(size=7);
13RUN;
14title;
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.