I have a question how to create a clustered graph is SAS.
The data is the following:
Year | County | Statewide |
2015 | 20.00% | 50.00% |
2016 | 40.00% | 32.00% |
2017 | 30.00% | 12.00% |
2018 | 70.00% | 0.00% |
2019 | 90.00% | 80.00% |
2020 | 100.00% | 90.00% |
2021 | 100.00% | 100.00% |
And the graph I am trying to create in SAS is the following:
Could you please help with the code for it? I was thinking to use proc gchart but then it looks like there should be two vbar arguments and I am not sure how to combine them.
Thank you!
@JaneS wrote:
I have a question how to create a clustered graph is SAS.
The data is the following:
Year County Statewide 2015 20.00% 50.00% 2016 40.00% 32.00% 2017 30.00% 12.00% 2018 70.00% 0.00% 2019 90.00% 80.00% 2020 100.00% 90.00% 2021 100.00% 100.00%
And the graph I am trying to create in SAS is the following:
Could you please help with the code for it? I was thinking to use proc gchart but then it looks like there should be two vbar arguments and I am not sure how to combine them.
Thank you!
To have reasonable control over the "clustering" you need to reshape the data a bit so that the same variable holds the county and statewide as values.
Here is an example:
data have; input Year County:percent8. Statewide:Percent8.; datalines; 2015 20.00% 50.00% 2016 40.00% 32.00% 2017 30.00% 12.00% 2018 70.00% 0.00% 2019 90.00% 80.00% 2020 100.00% 90.00% 2021 100.00% 100.00% ; proc transpose data=have out=need; by year; run; proc sgplot data=need; vbar year / response=COL1 group=_name_ groupdisplay=cluster; format col1 percent8.; label _name_='Source' col1 ='Value' ; run;
Proc transpose is a basic tool for reshaping the data. I did not get into any of the options for renaming variables.
I strongly suggest use of SGPLOT instead of Gchart as there are more options to control appearance and is where SAS is concentrating improvements.
Thank you so much, it was very helpful!
One more question what would be the best wat to show the percentage for each bar?
@JaneS wrote:
Thank you so much, it was very helpful!
One more question what would be the best wat to show the percentage for each bar?
I suggest looking at the documentation here: https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=grstatproc&docsetTarget=n...
Knowing where to look is half the battle and since the SGPLOT procedure has roughly 50 different statements, some with 30+ options spend some getting famililiar.
The option DATALABEL will show default labels of values, or if have a different variable in the data set you want to show then Datalabel=thatvariablename
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.