Hi,
I have a dataset which I want to create a bar chart looks like this
and this is the dataset I'm using
Obs | study_name | June | July | August |
1 | A | 20 | 16 | 39 |
2 | B | 18 | 18 | 6 |
3 | C | 19 | 1 | 5 |
4 | D | 87 | 65 | 115 |
5 | E | 63 | 55 | 62 |
6 | F | 81 | 104 | 87 |
7 | G | 73 | 19 | 49 |
8 | H | 189 | 69 | 79 |
9 | I | 28 | 6 | 8 |
10 | J | 87 | 83 | 52 |
11 | K | 0 | 0 | 0 |
12 | L | 0 | 0 | 0 |
13 | M | 4 | 1 | 1 |
14 | N | 1 | 0 | 2 |
15 | O | 212 | 159 | 304 |
data have;
input study_name $ June July August;
datalines;
A 20 16 39
B 18 18 6
C 19 1 5
D 87 65 115
E 63 55 62
F 81 104 87
G 73 19 49
H 189 69 79
I 28 6 8
J 87 83 52
K 0 0 0
L 0 0 0
M 4 1 1
N 1 0 2
O 212 159 304
;
Transpose the data so you have a single "month" variable to reference as the axis variable in a VBAR statement in proc sgplot.
data have; input study_name $ June July August; datalines; A 20 16 39 B 18 18 6 C 19 1 5 D 87 65 115 E 63 55 62 F 81 104 87 G 73 19 49 H 189 69 79 I 28 6 8 J 87 83 52 K 0 0 0 L 0 0 0 M 4 1 1 N 1 0 2 O 212 159 304 ; proc transpose data=have out=trans name=Month; by study_name; var June July August; run; Proc sgplot data=trans; vbar month / response=col1 group=study_name; run;
The get the legend entries to read "1 A" either make a variable with that value and transpose using it or create a format to show values of Study_name that way and apply the format in the Proc. Assign labels to Col1 and month to get nicer text or suppress entirely with XAXIS and YAXIS statements.
Please provide data as a data step for this example.
Also, include anything you've tried to plot this so far.
Looks like a vertical version of the Likert graph.
https://blogs.sas.com/content/graphicallyspeaking/2014/10/30/likert-graphs/
https://blogs.sas.com/content/graphicallyspeaking/2016/08/01/likert-graph-revisited/
Transpose the data so you have a single "month" variable to reference as the axis variable in a VBAR statement in proc sgplot.
data have; input study_name $ June July August; datalines; A 20 16 39 B 18 18 6 C 19 1 5 D 87 65 115 E 63 55 62 F 81 104 87 G 73 19 49 H 189 69 79 I 28 6 8 J 87 83 52 K 0 0 0 L 0 0 0 M 4 1 1 N 1 0 2 O 212 159 304 ; proc transpose data=have out=trans name=Month; by study_name; var June July August; run; Proc sgplot data=trans; vbar month / response=col1 group=study_name; run;
The get the legend entries to read "1 A" either make a variable with that value and transpose using it or create a format to show values of Study_name that way and apply the format in the Proc. Assign labels to Col1 and month to get nicer text or suppress entirely with XAXIS and YAXIS statements.
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.
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.