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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.