Written and maintained by CASRAI Editorial Board
Published
On this page
To create a scatter plot in SAS, execute the PROC SGPLOT procedure using the SCATTER statement with X= and Y= variable assignments, followed by a RUN; statement. This ODS Graphics procedure plots bivariate continuous observations as coordinate markers, allowing researchers to explore linear associations, assess bivariate distributions, inspect clustering patterns, and identify extreme outliers across experimental and observational datasets.
What SAS is used for in research
Statistical Analysis System (SAS) is an enterprise analytical system widely used in biostatistical research, clinical trials, epidemiological surveillance, econometric modeling, and institutional social sciences. In biomedical research and pharmaceutical development, SAS serves as the primary software for regulatory submissions to agencies such as the United States Food and Drug Administration (FDA) and the European Medicines Agency (EMA). Organizations working within Clinical Data Interchange Standards Consortium (CDISC) frameworks structure clinical records into Study Data Tabulation Model (SDTM) and Analysis Data Model (ADaM) domains, using validated SAS routines to execute primary and secondary efficacy analyses.
In academic and laboratory workflows, researchers use SAS for exploratory data analysis (EDA) before fitting formal inferential models. Examining bivariate distributions graphically allows investigators to assess linearity, evaluate homoscedasticity, observe clustering, and identify high-leverage data points. Rather than relying on summary statistics alone, visual inspection confirms whether empirical associations reflect genuine systemic patterns across the study population or arise from isolated anomalies.
Bivariate scatter displays in SAS connect directly to formal parametric and non-parametric testing. Observations highlighted in scatter plots often inform correlation testing in PROC CORR in SAS, where analysts compute Pearson product-moment, Spearman rank, or Hoeffding coefficients. Similarly, inspecting marginal scatter patterns complements univariate distribution checks performed in PROC UNIVARIATE in SAS. Graphical inspection also helps researchers avoid premature causal claims, as apparent associations can stem from unmeasured confounding such as omitted variable bias or simultaneous reciprocal relationships known as reverse causality.
How to install or access SAS
Researchers access SAS through three primary official channels: cloud-hosted academic software, institutional desktop installations, and containerized enterprise platforms. Users should obtain licenses and access environments exclusively through official SAS portals.
For students, university instructors, and independent academic researchers, the most accessible route is SAS OnDemand for Academics (ODA). This service delivers cloud-hosted SAS Studio through standard modern web browsers on Windows, macOS, Linux, and ChromeOS without requiring local software installation or administrative workstation privileges. It provides access to Base SAS procedures, SAS/STAT analytical routines, and high-resolution ODS Graphics engines, alongside dedicated personal cloud storage hosted by SAS Institute.
To access SAS OnDemand for Academics, follow these official registration steps:
- Navigate to the official SAS OnDemand for Academics portal at
sas.com/on-demand-for-academics. - Select the registration link to create a SAS Profile using an academic or personal email address, institutional affiliation, and country.
- Open the verification email sent by SAS User Authentication and confirm the account link.
- Log in to the SAS OnDemand for Academics dashboard and accept the academic end-user license agreement governing non-commercial research and instruction.
- Launch SAS Studio directly from the control dashboard to open the browser-based development workspace.
- Verify connectivity in the left-hand navigation pane by expanding the built-in
SASHELPlibrary containing standard reference datasets.
For enterprise research centers, institutional IT departments install SAS 9.4 on local workstations via the SAS Deployment Wizard or configure SAS Viya on private cloud infrastructure under institutional site licenses.
How to create a scatter plot in SAS step by step
Modern SAS creates scatter plots through the PROC SGPLOT (Statistical Graphics Plot) procedure under the ODS Graphics system. Unlike legacy SAS/GRAPH procedures like PROC GPLOT, PROC SGPLOT automates marker styling, dynamic axis scaling, typography, and vector output rendering without complex driver declarations.
To build a scatter plot, complete the following numbered steps:
- Prepare the dataset: Confirm that target analysis variables reside in an accessible SAS library, such as standard built-in data in
SASHELP.IRISorSASHELP.CLASS. - Initiate PROC SGPLOT: Open the procedure block by specifying
PROC SGPLOT DATA=dataset_name;. - Define coordinates: Call the
SCATTERstatement, setting the horizontal predictor withX=variableand the vertical response withY=variable. - Apply visual options: Append formatting options after a forward slash (
/), including categorical grouping (GROUP=), marker appearance (MARKERATTRS=), transparency (TRANSPARENCY=), or marker jitter (JITTER). - Configure axes and headings: Label axes and provide contextual titles using
XAXIS,YAXIS, andTITLEstatements. - Execute the procedure: Close the code block with
RUN;to generate the plot in the active ODS destination.
Basic bivariate scatter plot syntax
A basic scatter plot maps two continuous variables to Cartesian coordinates. The following example plots petal length against sepal length using Fisher’s classic botanical measurements in SASHELP.IRIS:
title "Fisher Iris Study: Sepal Length vs. Petal Length";
proc sgplot data=sashelp.iris;
scatter x=SepalLength y=PetalLength;
xaxis label="Sepal Length (mm)" grid;
yaxis label="Petal Length (mm)" grid;
run;
title;
The SCATTER statement specifies SepalLength on the horizontal axis and PetalLength on the vertical axis. The XAXIS and YAXIS statements provide measurement units and add reference gridlines via the GRID option to assist quantitative reading.
Categorical grouping and subgroup differentiation
When comparing observational cohorts, experimental arms, or species, the GROUP= option partitions markers across categories with distinct colors and shapes:
ods graphics on / attrpriority=none;
title "Iris Morphology Grouped by Taxonomic Species";
proc sgplot data=sashelp.iris;
scatter x=SepalLength y=PetalLength / group=Species
markerattrs=(size=7pt);
xaxis label="Sepal Length (mm)" grid;
yaxis label="Petal Length (mm)" grid;
keylegend / title="Species" position=topright;
run;
ods graphics / reset;
title;
The command ODS GRAPHICS ON / ATTRPRIORITY=NONE; instructs SAS to vary both marker shapes (circles, squares, triangles) and colors across categories. This dual encoding satisfies publication accessibility standards for monochrome printing and color-blind readers. The KEYLEGEND statement positions the categorical legend in the top-right corner of the canvas.
Overlaying regression lines and statistical confidence bands
Researchers frequently overlay analytical fit lines on scatter plots to evaluate trend directions. Adding the companion REG statement within the same PROC SGPLOT block produces ordinary least squares regression lines with statistical intervals:
title "Linear Fit with Mean Confidence Limits and Prediction Bands";
proc sgplot data=sashelp.iris;
scatter x=SepalLength y=PetalLength / markerattrs=(symbol=circlefilled size=5pt color=cx4A7EBB);
reg x=SepalLength y=PetalLength / clm cli lineattrs=(color=cxD9534F thickness=2px);
xaxis label="Sepal Length (mm)" grid;
yaxis label="Petal Length (mm)" grid;
run;
title;
The REG statement generates two distinct statistical bounds:
- Confidence limits for the mean (
CLM): A shaded 95% confidence band reflecting precision in estimating the population regression line. This band narrows in regions dense with observations. - Confidence limits for individual observations (
CLI): A wider 95% prediction band reflecting total variance, encompassing parameter uncertainty and random observation error. Approximately 95% of future observations fall within these limits.
For non-linear relationships, analysts use the LOESS statement for local polynomial regression smoothing or PBSPLINE for penalized B-spline curves.
Mitigating overplotting with jitter and transparency
When plotting integer measurements, discrete survey scales, or large-sample cohorts, overlapping markers obscure observation density. SAS offers two parameters in the SCATTER statement to resolve overplotting:
title "Overplotting Remediation via Jittering and Transparency";
proc sgplot data=sashelp.class;
scatter x=Age y=Height /
jitter
jitterwidth=0.08
transparency=0.4
markerattrs=(symbol=circlefilled size=9pt color=navy);
xaxis label="Age (Years)" values=(11 to 16 by 1) grid;
yaxis label="Height (Inches)" grid;
run;
title;
The JITTER option introduces subtle random offsets around identical values, while JITTERWIDTH=0.08 constrains this spread to 8% of the category interval. Setting TRANSPARENCY=0.4 applies 40% alpha transparency, causing stacked markers to accumulate visual density and reveal high-frequency clusters.
Conditioned lattice plots with PROC SGPANEL
When visualizing complex multi-factor studies, combining categories on a single plot can cause visual confusion. In such cases, PROC SGPANEL organizes observations into a multi-panel lattice:
title "Morphological Measurements Paneled by Species";
proc sgpanel data=sashelp.iris;
panelby Species / columns=3 rows=1 uniscale=all spacing=5;
scatter x=SepalLength y=PetalLength / markerattrs=(symbol=circlefilled size=6pt);
reg x=SepalLength y=PetalLength / lineattrs=(color=red thickness=1.5px);
run;
title;
The PANELBY Species statement partitions output into three panels sharing identical horizontal and vertical coordinates via UNISCALE=ALL, allowing direct visual comparison across species.
How to read the output
Interpreting a SAS scatter plot involves evaluating bivariate geometry, residual dispersion, and subgroup distributions. Researchers review scatter output as an exploratory diagnostic step, comparing visual findings with broader types of graphs in statistics and computational methods such as scatter plots in Python.
Analysts evaluate five primary visual dimensions when reviewing output:
- Direction and monotonicity: Check whether points demonstrate a positive slope (variables rise together), an inverse negative slope (one variable declines as the other rises), or zero slope (random dispersion indicating independence). Monotonicity confirms whether directional trends hold consistently across the measurement range.
- Curvature and linearity: Determine whether the point distribution follows a straight trajectory or exhibits curvature, such as logarithmic leveling or polynomial turns. Non-linear patterns alert researchers that standard linear models are misspecified, requiring non-linear parameterization or spline transformations.
- Dispersion and correlation strength: Assess how closely points cluster around the regression line. A compact envelope indicates strong correlation and high explained variance, whereas a wide, scattered cloud indicates weak association.
- Homoscedasticity versus heteroscedasticity: Inspect the vertical spread of points across the horizontal predictor range. Uniform vertical dispersion across all values confirms homoscedasticity. A fan-shaped pattern—where spread widens at higher predictor values—signals heteroscedasticity, indicating the need for robust variance estimation or logarithmic transformations.
- Outliers and leverage points: Locate isolated observations far from the main data cluster. Extreme observations on both axes can disproportionately influence fitted slopes. Identifying these values prompts checks for transcription errors or genuine rare cases requiring sensitivity analysis.
When evaluating regression overlays, distinguish the narrow mean confidence band (CLM) from the wider prediction interval (CLI). If observed points fall outside the CLI boundaries frequently, researchers should investigate model assumptions and possible omitted interactions.
Troubleshooting SAS
When compiling graphics in SAS, the execution log provides error messages and warning codes that point directly to technical fixes.
The following table summarizes common issues, underlying causes, and technical solutions:
| Encountered Log Message or Visual Issue | Root Cause | Verified Technical Resolution |
|---|---|---|
ERROR: Variable [name] not found. |
Variable name misspelled, casing mismatch in delimited imports, or variable absent from dataset. | Run PROC CONTENTS DATA=your_dataset; RUN; to verify exact column names in the table descriptor. |
WARNING: The number of group levels exceeds the maximum number of style elements. |
The GROUP= variable contains more unique categories than the active ODS style provides distinct colors or symbols. |
Confirm the classification variable is categorical. Define custom attributes using STYLEATTRS DATACONTRASTCOLORS=(...) DATASYMBOLS=(...);. |
| Dense point clustering obscuring sample density. | Identical or rounded observation values stacking directly at coordinates. | Specify JITTER JITTERWIDTH=value and TRANSPARENCY=0.3..0.7 in the SCATTER statement to disperse markers and enable alpha blending. |
| Axis tick values overlapping or formatted poorly. | Continuous axis tick labels have excessive decimal places or tight intervals. | Apply explicit tick spacing using XAXIS VALUES=(start TO end BY increment) VALUEATTRS=(SIZE=9pt); or assign a numeric FORMAT. |
WARNING: The requested graph size exceeds the available display area. |
Canvas dimensions exceed target document margins or display boundaries. | Adjust canvas size before running the procedure using ODS GRAPHICS ON / RESET WIDTH=6.5IN HEIGHT=4.5IN IMAGEMAP=OFF;. |
| Regression line or confidence band fails to display. | Missing values present in coordinate variables or non-numeric formatting applied to the axis variable. | Confirm both variables are numeric and exclude missing observations using a WHERE clause (e.g., WHERE X IS NOT MISSING AND Y IS NOT MISSING;). |
Reviewing the SAS log confirms the count of observations read, identifies records omitted due to missing values, and ensures output figures meet audit and reproducibility standards.
Free alternatives to SAS
While SAS remains an enterprise standard in regulated clinical research, many academic laboratories and open-science projects use free, open-source statistical platforms. Open-source environments eliminate licensing overhead and support public computational reproducibility.
The following table compares open-source software tools for producing research scatter plots:
| Software Ecosystem | Primary Visualization Package | Standard Scatter Plot Syntax | Statistical Overlay Support | Key Research Advantages |
|---|---|---|---|---|
| R Language | ggplot2 (Tidyverse) |
ggplot(df, aes(x, y)) + geom_point() |
geom_smooth(method="lm", se=TRUE) or method="loess" |
Grammar of graphics architecture, publication-ready themes, extensive CRAN biostatistical packages, and Quarto documentation. |
| Python | matplotlib / seaborn |
plt.scatter(x, y) or sns.scatterplot(data=df, x='x', y='y') |
sns.regplot(x='x', y='y', data=df) |
Direct integration with scientific libraries (NumPy, SciPy, Pandas), machine learning tools, and interactive notebooks. |
| Julia | Plots.jl / Makie.jl |
scatter(x, y) |
Linear fit recipes and polynomial trendlines via GLM.jl |
Fast execution performance, handling millions of observations without memory strain, and mathematical syntax. |
| GNU PSPP | Native Graphics Engine | GRAPH /SCATTERPLOT(BIVAR)=x WITH y. |
Basic bivariate scatter displays and regression output tables | Open-source SPSS syntax replacement, zero cost on Linux and Windows, suitable for social science education. |
Research workflows often combine these environments: clinical data verification and regulatory tables are compiled in SAS, while exploratory figures and interactive dashboards are built in R or Python.
Frequently asked questions
How do you create a basic scatter plot in SAS?
To create a basic scatter plot in SAS, invoke the PROC SGPLOT procedure, specify the input dataset with the DATA= argument, declare the SCATTER statement defining your independent horizontal variable with X= and dependent vertical variable with Y=, and conclude with the RUN; statement. For example: proc sgplot data=sashelp.iris; scatter x=SepalLength y=PetalLength; run;.
How do you add a regression or best-fit line to a scatter plot in SAS?
To add a regression trendline to a scatter plot in SAS, include the REG statement within the same PROC SGPLOT execution block alongside the SCATTER statement. Specifying reg x=variable1 y=variable2 / clm cli; overlays an ordinary least squares linear regression line along with shaded 95% confidence limits for the mean response (CLM) and individual prediction limits (CLI). For non-linear curvature, use the LOESS statement instead.
How do you create a grouped scatter plot by category?
To create a grouped scatter plot in SAS, add the GROUP=category_variable option after a forward slash in the SCATTER statement within PROC SGPLOT. SAS automatically partitions data points by the unique values of the grouping variable, assigning unique colors and marker symbols to each cohort. To ensure both colors and marker glyphs vary simultaneously, precede the procedure with ODS GRAPHICS ON / ATTRPRIORITY=NONE;.
How do you customize markers and labels in a SAS scatter plot?
Customize marker appearance using the MARKERATTRS=(options) parameter inside the SCATTER statement, where you specify attributes such as SYMBOL=circlefilled, SIZE=7pt, and COLOR=blue. To display observation data labels directly beside plotted markers, append DATALABEL=label_variable, and control font styling using DATALABELATTRS=(family='Arial' size=8pt).
What is the difference between PROC SGPLOT and PROC GPLOT for scatter plots?
PROC SGPLOT is modern SAS ODS Graphics syntax introduced to replace legacy SAS/GRAPH procedures like PROC GPLOT. PROC SGPLOT automates aesthetic styling, dynamically adjusts axis ranges, formats typography cleanly, and produces high-resolution output across modern display devices without requiring manual GOPTIONS, AXIS, or SYMBOL statement declarations required by legacy PROC GPLOT.
Sources
- SAS Institute: SCATTER Statement, SAS 9.3 ODS Graphics: Procedures Guide, checked 2026-11-22
- SAS Institute: Grouping a Scatter Plot, SAS 9.3 ODS Graphics: Procedures Guide, checked 2026-11-22
- SAS Institute: Adding Prediction and Confidence Bands to a Regression Plot, SAS 9.3 ODS Graphics: Procedures Guide, checked 2026-11-22
- SAS Institute: SAS OnDemand for Academics, checked 2026-11-22
- NIST/SEMATECH: 1.3.3.26. Scatter Plot, e-Handbook of Statistical Methods, checked 2026-11-22
- Tidyverse: Points — geom_point, ggplot2 Reference Documentation, checked 2026-11-22
- Matplotlib Development Team: matplotlib.pyplot.scatter, Matplotlib 3.11 Documentation, checked 2026-11-22
Data: SAS Scatter Plot Procedures and Statement Capabilities Comparison
Comparison of SAS statistical graphics procedures and statements for generating bivariate scatter plots, detailing statement syntax, grouping support, fit line overlay options, and marker customization capabilities compiled from SAS 9.3 and 9.4 ODS Graphics documentation.
| Procedure and Statement | Primary Plot Type | Grouping Syntax | Trend Overlay Support | Marker Customization Options |
|---|---|---|---|---|
| PROC SGPLOT SCATTER | Single-cell 2D bivariate scatter plot | GROUP=variable option | REG, LOESS, PBSPLINE, ELLIPSE statements | MARKERATTRS, JITTER, TRANSPARENCY, DATALABEL |
| PROC SGPLOT REG | Scatter plot with fitted linear regression line | GROUP=variable option | CLI, CLM confidence limits, DEGREE=n polynomial | MARKERATTRS, LINEATTRS |
| PROC SGPLOT LOESS | Scatter plot with non-parametric local regression | GROUP=variable option | CLM confidence limits, SMOOTH=value option | MARKERATTRS, LINEATTRS |
| PROC SGPANEL SCATTER | Multi-panel conditioned lattice scatter plots | PANELBY statement + GROUP= option | REG, LOESS, or ELLIPSE companion statements | MARKERATTRS, JITTER, TRANSPARENCY, DATALABEL |
| PROC SGSCATTER PLOT | Comparative multi-variable scatter plot matrix/panel | GROUP=variable option | REG= or LOESS= options directly in statement | MARKERATTRS, GRID, DATALABEL |
| PROC SGSCATTER MATRIX | Full pairwise scatter plot matrix across variables | GROUP=variable option | ELLIPSE=, DIAGONAL=(HISTOGRAM DENSITY) options | MARKERATTRS |
Sources
- PROC SGPLOT: SCATTER Statement, SAS 9.3 ODS Graphics Procedures Guide (accessed 2026-11-22)
- Grouping a Scatter Plot, SAS 9.3 ODS Graphics Procedures Guide (accessed 2026-11-22)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







