Hello,
I'm trying to produce the stacked bar chart using the below data but not able to achieve the desired results. I'm getting the desired graph in the excel without any issue. Please help.
Tenure 1 Yr 2 yr 3 Yr 4 Yr 5 Yr 6 to 10 yr over 10yrs
prct 9.00 8.00 7.00 6.00 6.00 24.00 41.00
I have Attached the graph produced through excel. I'm trying to achieve same using the SAS. Tried proc gchart but not working.
Thanks.
SAS does not work like Excel. You will need to transform your data structure from multi-column to classified. You need data as follows:
Category Tenure Value
1 1 Yr 9.0
1 2 Yr 8.0
and so on. Then, you can use the following statement:
proc sgplot data= <your dataset>;
vbar Category / Response=value Group=Tenure;
run;
You can have additional categories to get multiple stacked bars.
SAS does not work like Excel. You will need to transform your data structure from multi-column to classified. You need data as follows:
Category Tenure Value
1 1 Yr 9.0
1 2 Yr 8.0
and so on. Then, you can use the following statement:
proc sgplot data= <your dataset>;
vbar Category / Response=value Group=Tenure;
run;
You can have additional categories to get multiple stacked bars.
Thanks Sanjay. I was trying it in different way like below. I was able to stack the bars but I'm seeing gap between the bars. Not sure why.
proc sgplot data=totacct_tenure2;
title 'Distribution of Accounts by Tenure';
series x= Tenure y='1 yr'n /lineattrs=(color= Blue thickness=30 ) ;
series x= Tenure y='2 yr'n / lineattrs=(color= '#13478C' thickness=15 );
series x= Tenure y='3 yr'n / lineattrs=(color='#90EE90' thickness=15);
series x= Tenure y='4 yr'n / lineattrs=(color= yellow thickness=15);
series x= Tenure y='5 yr'n / lineattrs=(color= black thickness=15);
series x= Tenure y='6 to 10 yrs'n / lineattrs=(color=brown thickness=15);
series x= Tenure y='over 10 yrs'n / lineattrs=(color= pink thickness=15);
keylegend / location=Outside Position=right down=7 ;
yaxis label= "Percentage" grid values=( 0 to 100 by 10 ) ;
Xaxis label="% of Accounts";
run;
I can't guess why you are using a SERIES statement to create stacked bars. See "Getting Started" section in Graphically Speaking for many examples of how SAS procedures work. It may not help to try to use Excel methodology with SAS.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.