Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mona4u
Lapis Lazuli | Level 10

Hi, 

I have a dataset which I want to create a bar chart looks like this 

 

and this is the dataset I'm using 

 

 

 

 

Obsstudy_nameJuneJulyAugust
1A201639
2B18186
3C1915
4D8765115
5E635562
6F8110487
7G731949
8H1896979
9I2868
10J878352
11K000
12L000
13M411
14N102
15O212159304

 

 Capturebbbb.PNG

 
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


;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

4 REPLIES 4
Reeza
Super User

Please provide data as a data step for this example. 

Also, include anything you've tried to plot this so far. 

 

mona4u
Lapis Lazuli | Level 10
just edit it
ballardw
Super User

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.

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1677 views
  • 2 likes
  • 4 in conversation