SAS Visual Analytics

Dashboards, reports, BI and analytics - all from a single interface.
BookmarkSubscribeRSS Feed
DavidsM
Fluorite | Level 6

Dear SAS Community,

 

I would like to plot both an overall and a stratified graph on the same graph procedure. I have been using the following procedures for the overall and stratified graphs separately, but I would like to combine them into one graph showing the percentages for both the overall and stratified graphs. 

 

/*Creating Data with Categorical Variables for Satisfaction and Age Categories*/
Data Customer_response; set Origina_Data;
if Response="Satisfied" then Satisfaction=1;
else if Response "Not Satisfied" then Satisfaction=2;

if Age lt 35 then Age_Category=1
else if Age ge 35 then Age_Category=2;
run;

 

 

Below is that SAS code that works for the overall graph.

 

 

/*Creates an Overall Graph for the Satisfaction Variable showing percentages */
title; /* Removes all titles */
Proc sgplot data=Customer_response;
format Satisfaction.;
styleattrs datacolors=(VIGB VIPK) ;
vbar Satisfaction / group=Satisfaction stat=percent; /* Creates a vertical bar chart showing percentages */
LABEL Satisfaction='Satisfaction Category';
XAXIS LABEL = 'Satisfaction';
XAXIS VALUES =("1" "2");
YAXIS LABEL = 'Proportion of Participants According to Satisfaction';
keylegend / title="Customer Satisfaction";
run;

 

 

Below is the program that seems to produce the desired age stratified graph.


/* Frequency plot of percentages for two variables */
Proc freq data=Customer_response;
tables Age_Category *Satisfaction / plots=FreqPlot(twoway=cluster scale=Percent) out=Freq2Out;
run;


/* Dividing by 100 and apply PERCENTw.d format*/
Data Freq2Out;
set Freq2Out;
Percent = Percent / 100;
format Percent PERCENT5.;
run;

 

 

/*Graph showing Satisfaction Stratified by Age Categories*/
ods listing style=listing;
ods graphics / width=7.8in height=7in;
*title 'Graph showing Satisfaction Stratified by Age Categories';
Proc sgplot data=Freq2Out;
format Satisfaction.;
styleattrs datacolors=(VIGB VIPK) ;
vbar Age_Category / group=Satisfaction groupdisplay=cluster response=Percent;
XAXIS LABEL = 'Age Category';
YAXIS LABEL = 'Proportion of Participants According to Satisfaction Categories'
VALUES =("1" "2") VALUESDISPLAY=("Satisfied" "Not Satisfied");
keylegend / title="Satisfaction";
run;

 

Those two graphs are currently drawn separately, but I want to have both the overall and stratified graphs combined on the same graph in a single procedure, with the overall graph on the left side and the stratified on the right side of the graph creates. I will be glad to receive assistance from the community. If there is any other more efficient procedure, I would like to see a sample code that I can use to produced those graphs.

 

Thank you.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 0 replies
  • 606 views
  • 0 likes
  • 1 in conversation