BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ch_ndra
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

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.

 

See:  https://blogs.sas.com/content/graphicallyspeaking/2013/09/07/bar-charts-with-stacked-and-cluster-gro...

View solution in original post

3 REPLIES 3
Jay54
Meteorite | Level 14

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.

 

See:  https://blogs.sas.com/content/graphicallyspeaking/2013/09/07/bar-charts-with-stacked-and-cluster-gro...

Ch_ndra
Calcite | Level 5

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;

Jay54
Meteorite | Level 14

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1248 views
  • 0 likes
  • 2 in conversation