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.
Dear JeffMeyers,
I do not have variables for time (T) or status because I am not conducting time-to-event analysis. I am just obtaining descriptive visualization of the data for the overall and the stratified.
Any other procedure that can produce these graphs would be fine. I look forward to receiving assistance either through modification of my code or any other approach or procedure.
Thanks
Dear JeffMeyers,
Thank you for the reply.
What do the T and Status variables represent in the Proc Lifetest procedure in this case?
I look forward to receiving some clarification.
Thank you.
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.
With some work, there might be a way to simplify this down into a single call to PROC SGPANEL. But since you already have code that creates the two plots you want, you can just put them together in a side by side panel using ODS LAYAOUT GRIDDED and ODS REGION statements as illustrated in this note.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.