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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 961 views
  • 2 likes
  • 4 in conversation