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 this code



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;
yaxis grid display=(nolabel);
Xaxis display=(nolabel);
run;

 

 

which produces this result in the picture. 

Note that the months in the bar chart are not displayed as they are in their order, they have alphabetical order. 

I tried to find an option to change that but I couldn't find. Also, I don't need to display the study_name in the chart and don't know how to change the default. 

 

Capture14.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Add DISCRETEORDER=DATA to your XAXIS statement, and set the legend title to be "".

 

roc sgplot data=trans;
   vbar month / response=col1 group=study_name;
    yaxis grid display=(nolabel);
   Xaxis display=(nolabel) discreteorder=data;
   keylegend / title="";
run;

Hope this helps!

Dan

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

It is always better to use numbers to represent calendar or clock values. So if June is 6 and July is 7 and August is 8, these will automatically plot in the desired order.

 

Also, instead of data as you have shown it, you could do less programming if you re-organzied the data before you create the SAS data set, something like

 

data have;
input study_name $ month value;
datalines;
A 6 20
A 7 16
A 8 39
B 6 18
--
Paige Miller
DanH_sas
SAS Super FREQ

Add DISCRETEORDER=DATA to your XAXIS statement, and set the legend title to be "".

 

roc sgplot data=trans;
   vbar month / response=col1 group=study_name;
    yaxis grid display=(nolabel);
   Xaxis display=(nolabel) discreteorder=data;
   keylegend / title="";
run;

Hope this helps!

Dan

PaigeMiller
Diamond | Level 26

@DanH_sas wrote:

Add DISCRETEORDER=DATA to your XAXIS statement, and set the legend title to be "".

 

roc sgplot data=trans;
   vbar month / response=col1 group=study_name;
    yaxis grid display=(nolabel);
   Xaxis display=(nolabel) discreteorder=data;
   keylegend / title="";
run;

Hope this helps!

Dan


It might help get the right plot, but it is still a better practice to use numbers for calendar time periods rather than words like "August","June","July". Then, the discreteorder option is not needed. And there are many other potential benefits as well in the long run.

--
Paige Miller

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
  • 3 replies
  • 805 views
  • 1 like
  • 3 in conversation