Published on :
Reporting SASHELP

Generating Scatterplot Matrices with PROC SGSCATTER

This code is also available in: Deutsch Español Français
The script begins by configuring ODS (Output Delivery System) options for graphic output, including the image save path, format (PNG), and dimensions. It then generates a first matrix for 'sashelp.cars' vehicle data, filtering specific types. Two additional matrices are created for the 'sashelp.iris' dataset, one using the standard 'matrix' statement and the other the 'compare' statement for cross scatterplots. Each visualization includes titles, variable labels, and marker style options.
Data Analysis

Type : SASHELP


Data comes from SAS's built-in libraries, 'sashelp.cars' and 'sashelp.iris', which are available by default in the SAS environment.

1 Code Block
ODS Configuration
Explanation :
This block configures the Output Delivery System (ODS) to direct graphic output to a specified path and sets graphic options such as resetting parameters, color attribute priority, border, image dimensions, image name ('matrix1'), format ('png'), and antialiasing.
Copied!
1ods listing gpath="/home/nicolasdupont0/resources_github/Graph/Correlation/img" image_dpi=200;
2 
3ods graphics /
4 reset = all attrpriority=color border = no width=800px height=800px
5 imagename = "matrix1" imagefmt = png outputfmt = png antialiasmax = 10000;
2 Code Block
PROC SGSCATTER
Explanation :
This procedure generates a scatterplot matrix for the `sashelp.cars` dataset, filtering vehicle types 'Sedan' and 'Sports'. It assigns labels to the variables 'mpg_city' and 'mpg_highway', then creates the matrix using 'mpg_city', 'mpg_highway', 'horsepower', and 'weight' with 0.5 transparency and filled circle markers.
Copied!
1PROC SGSCATTER DATA=sashelp.cars(where=(type in ('Sedan' 'Sports')));
2 title 'Scatterplot Matrix for Vehicle Type';
3 label mpg_city='City';
4 label mpg_highway='Highway';
5 matrix mpg_city mpg_highway horsepower weight / transparency=0.5 markerattrs=(symbol=CircleFilled);
6RUN;
3 Code Block
ODS Configuration
Explanation :
This block configures the Output Delivery System (ODS) for the second scatterplot matrix. It resets graphic options and sets a new image name ('matrix2') while maintaining the same dimensions and formats.
Copied!
1ods graphics /
2reset = all attrpriority=color border = no width=800px height=800px
3imagename = "matrix2" imagefmt = png outputfmt = png antialiasmax = 10000;
4 
4 Code Block
PROC SGSCATTER
Explanation :
This procedure generates a scatterplot matrix for the `sashelp.iris` dataset. The title is 'Scatterplot Matrix for Iris Data'. The matrix is constructed from the variables 'SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth', grouped by 'Species', with 0.5 transparency and filled circle markers.
Copied!
1PROC SGSCATTER DATA=sashelp.iris;
2 title "Scatterplot Matrix for Iris Data";
3 matrix SepalLength SepalWidth PetalLength PetalWidth / group=Species transparency=0.5 markerattrs=(symbol=CircleFilled);
4RUN;
5 Code Block
ODS Configuration
Explanation :
This block configures the Output Delivery System (ODS) for the third scatterplot matrix. It resets graphic options and sets a new image name ('matrix3') while maintaining the same dimensions and formats.
Copied!
1ods graphics /
2reset = all attrpriority=color border = no width=800px height=800px
3imagename = "matrix3" imagefmt = png outputfmt = png antialiasmax = 10000;
4 
6 Code Block
PROC SGSCATTER
Explanation :
This procedure generates a scatterplot matrix for the `sashelp.iris` dataset, but uses the `compare` statement to create a cross scatterplot matrix. The variables 'SepalLength' and 'SepalWidth' are compared to 'PetalLength' and 'PetalWidth', grouped by 'species', with filled circle markers.
Copied!
1PROC SGSCATTER DATA=sashelp.iris;
2 title "Scatterplot Matrix for Iris Data";
3 compare x=(SepalLength SepalWidth)
4 y=(PetalLength PetalWidth)
5 / group=species markerattrs=(symbol=CircleFilled);
6RUN;
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.
Copyright Info : Created : 03/11/2017 (fr), Last update : 03/11/2017, Author(s) : Nicolas Dupont