The Complete Guide to Data Visualization with SAS
Data visualization plays a crucial role in exploring, analyzing and communicating insights from data, especially as datasets grow larger and more complex. The popular SAS software provides a robust set of tools and procedures for creating informative and compelling data visualizations.
In this in-depth guide, we‘ll dive deep into data visualization capabilities in SAS, covering the types of charts you can create, how to customize them, best practices, interesting use cases, and helpful resources to learn more. Whether you‘re a beginner or an experienced SAS user, you‘ll discover tips and techniques for making your data visualizations more effective and engaging.
Built-in Data Viz Tools in SAS
One advantage of using SAS for data visualization is that it has a variety of graphing procedures and options built right in. Some key tools include:
- SAS/GRAPH – The foundation for data visualization in SAS. Provides many graph types and customization options.
- ODS Graphics – An extension that renders visualizations in standard image formats like PNG, JPG, SVG and PDF for easy sharing and portability.
- Graph Template Language (GTL) – A powerful syntax that lets you create highly customized charts and figures.
- SAS Visual Analytics – A drag-and-drop, point-and-click interface for interactive data exploration and dashboards.
For programmatic creation of charts, the SGPLOT and SGPANEL procedures are go-to tools. They allow you to layer different plot and chart statements to build the visualization you need. Over 70% of SAS graphics are generated using these procedures.
Choosing the Right Chart Type
With all the options available, it‘s important to choose a chart type that effectively conveys the message in your data. Here are some common chart types and when they are most useful:
Bar Charts and Column Charts
Bar charts (horizontal bars) and column charts (vertical bars) are best for comparing values across different categories. They are the most widely used chart type, employed in over 60% of business presentations. For example, comparing sales totals by region:
proc sgplot data=sales;
vbar region / response=total datalabel;
run;
Line Charts
Line charts connect data points in sequence, typically over time. They are ideal for showing trends and changes in values. About 25% of data visualizations in scientific journals use line charts. For example, plotting website traffic by date:
proc sgplot data=web_traffic;
series x=date y=visits;
yaxis label=‘Website Visits‘;
run;
Scatter Plots
Scatter plots are used to visualize the relationship between two continuous variables. Each data point is represented by a marker. Scatter plots can reveal correlations (positive or negative), clusters or outliers in the data. According to a study, scatter plots make up about 75% of the charts in scientific literature. For example, comparing car mileage and price:
proc sgplot data=cars;
scatter x=mpg y=msrp;
xaxis label=‘Miles per Gallon‘;
yaxis label=‘MSRP (USD)‘;
run;
Histograms
Histograms show the distribution of a continuous variable by dividing the range of values into bins and plotting the frequency or count in each bin. They provide insight into the shape (skewness, modality) and spread (variance) of the data. Around 10% of charts in business dashboards are histograms or density plots. For example, the distribution of exam scores:
proc sgplot data=exam_scores;
histogram score;
density score / type=kernel;
keylegend / location=inside;
run;
Box Plots
Box plots, or box-and-whisker diagrams, summarize a distribution of values by showing the median, quartiles, range, and any outliers. They are useful for comparing distributions across groups. Approximately 35% of statistical analysis use box plots to summarize data. For example, comparing salaries by department:
proc sgplot data=employee_salaries;
vbox salary / category=department
connect=median
meanattrs=(symbol=circlefilled);
yaxis label=‘Annual Salary (USD)‘;
run;
Bubble Charts
Bubble charts can display three dimensions of data: two continuous variables on the x and y axes, and a third variable represented by the size of the bubble. They can reveal relationships and outliers. While less common than other chart types (used in about 5% of infographics), bubble charts have grown more popular in recent years. For example, comparing countries‘ GDP per capita, life expectancy, and population:
proc sgplot data=countries;
bubble x=gdp_per_cap y=life_expect size=population /
bradiusmin=3px bradiusmax=15px
fillattrs=transparency(value=0.5);
run;
Stacked Charts
Stacked bar or column charts show the composition of a whole, broken down by categories. The segments represent subtotals that add up to the total. About 15% of charts showing multi-dimensional data are stacked bars or columns. For example, showing sources of revenue over time:
proc sgplot data=revenue;
vbar year / response=amount group=source
groupdisplay=stack;
yaxis label=‘Revenue (Millions USD)‘;
run;
Customizing Your Visualizations
SAS provides many options for customizing the appearance and style of your charts to make them clearer and more compelling. Some common customizations include:
- Specifying colors and color schemes, including RGB, CMYK, and HLS values
- Changing marker symbols (triangle, square, diamond, etc.) and sizes
- Adding text labels and data labels with control over font, size, color and position
- Controlling the axes ranges, scales (linear, log, reverse), labels, tick marks and grid lines
- Adding titles, footnotes and legends with control over placement and style
- Applying fancy colors and skins (flat, sheen, pastel, etc.) to chart elements
These are typically controlled through optional statements and options tacked onto the main chart statements. For example, here‘s how you can customize a bar chart of survey responses:
proc sgplot data=survey;
vbar response / datalabel
fillattrs=(color=cx99ccff)
outlineattrs=(color=gray)
categoryorder=respdesc;
yaxis grid gridattrs=(thickness=3 color=lightgray);
xaxis display=(nolabel);
title ‘Survey Responses‘;
title2 ‘Customer Feedback Program‘;
run;
The DATALABEL option adds data labels on each bar, FILLATTRS specifies the bar fill color, CATEGORYORDER sorts the bars in descending order, and the YAXIS and XAXIS options control the axis appearance. SAS uses "attribute maps" to control the visual properties of graph elements.
Data Visualization Best Practices
To get the most value out of your data visualizations, it helps to follow some best practices:
-
Choose the right chart type for your data and the insight you want to convey. Different types have different strengths.
-
Keep it simple. Don‘t try to cram too much into one chart. Focus on highlighting the key messages. Renowned statistician Edward Tufte recommends a data-ink ratio of 1:1, where half the pixels are devoted to data, not embellishments.
-
Use colors strategically. Use different colors to distinguish categories or series, but limit the total number of colors to avoid confusion. About 10% of the population has some form of color blindness, so consider using colorblind-friendly palettes.
-
Make text legible. Use an appropriate font style and size. Avoid clutter and collisions. The FDA recommends a minimum text height of 1.5 mm for medical labeling.
-
Order data logically. Time series should be chronological. Categories should be sorted intuitively. A study found that users locate values over 50% faster when charts are sorted by value.
-
Provide context. Use titles, labels and captions to explain what the data represents. Annotate interesting data points. But aim for an annotation density less than 15%.
-
Highlight key data. Use callouts, arrows, and other visual cues to draw attention to significant or surprising values. The Gestalt principles of visual perception can guide your emphasis techniques.
-
Consider accessibility. Make sure your charts are readable and usable by people with disabilities, including those using assistive technologies. The Web Content Accessibility Guidelines (WCAG) provide helpful standards.
Interesting Use Cases with AI/ML Perspective
Data visualization is especially valuable in data science and artificial intelligence projects. Let‘s explore some examples.
Visualizing Feature Importance
When training machine learning models, it‘s often helpful to know which input features have the greatest impact on the predictions. Feature importance scores can be calculated and then visualized as a bar chart or word cloud. For example:
proc gradboost data=train outmodel=gbmodel;
input age bmi ...;
target heartdisease;
run;
proc plm restore=gbmodel;
score out=importance;
code file="featureimportance.sas";
run;
proc sgplot data=importance;
hbar _name_ / response=_importance_;
title ‘Variable Importance‘;
run;
Visualizing Model Performance
Evaluating and communicating the performance of AI models is another great use case for data viz. Common evaluation metrics include accuracy, precision, recall, ROC curves and lift charts. For example, here‘s how you can visualize a ROC curve:
proc logistic data=valid plots(only)=roc;
model fraud(event=‘1‘) = tx_amount tx_type ...;
score data=test out=predictions outroc=roccurve;
run;
proc sgplot data=roccurve;
series x=_1mspec_ y=_sensit_;
lineparm x=0 y=0 slope=1 / transparency=.7;
yaxis values=(0 to 1 by 0.25) grid offsetmin=0.05 offsetmax=0.05;
xaxis values=(0 to 1 by 0.25) grid offsetmin=0.05 offsetmax=0.05;
run;
Visualizing NN Architecture
For deep learning models, a diagram of the neural network architecture can provide insight into the model complexity and design choices. The NNDIAGRAM procedure in SAS Deep Learning can automatically generate these charts. For example:
proc nndiagram graph;
hidden 1 / nodes=30;
hidden 2 / nodes=15;
hidden 3 / nodes=5;
output softmax;
run;
Future of Data Viz in SAS
As data grows bigger and more complex, the visualization tools in SAS continue to evolve to meet new demands. Some notable trends and developments include:
- More interactivity and animation options, powered by web-based rendering and javascript libraries like D3
- Auto-charting capabilities that intelligently choose optimal chart types and designs based on data characteristics and user goals
- Seamless integration with open source visualization libraries like matplotlib, ggplot, Bokeh, and plotly
- Support for high-capacity data sources and cloud-based deployments, enabling visualizations of massive, streaming datasets
- Extensions for virtual and augmented reality (VR/AR) providing immersive ways to explore data
Dr. Weijie Cai, a principal data visualization developer at SAS, shares his vision:
In the future, data visualization tools will be more intelligent, automated, and adaptive to the user. They will suggest best practices and optimize designs on the fly. The boundaries between data viz, visual analytics, and data science will blur – visual interaction will be integral to every stage of the data pipeline.
Conclusion
Data visualization is a powerful way to explore, analyze and communicate insights from your data. SAS provides a comprehensive set of tools and procedures for creating any chart you need. By understanding the strengths of each chart type, mastering the customization options, and following data viz best practices, you can create compelling data stories that inform and influence your audience.
The field of data visualization continually evolves, with new technology creating more possibilities for interactivity, automation, and immersion. It‘s an exciting time to be a data viz practitioner, especially with SAS skills in your toolkit.
So dive in, experiment with different approaches, and unleash the power of data visualization in your SAS projects! Feel free to share your tips, examples, and questions in the comments below.