Desktop productivity for business analysts and programmers

Monthly Box Plot

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

Monthly Box Plot

 Hi, I have a dataset with over 80,000 observations and I want to make a monthly box plot but get an error that the data isn't in order.

I want it to look like this:

Screen Shot 2018-06-20 at 11.39.18 AM.png

 

I used this code:

proc boxplot data=dataname;
plot Load*Month;
run;

And here's how some of the data looks like and goes on for years:

input load day month temperature
datalines:
12345 0 12 35
12456 1 12 33
12222 2 12 32
14532 3 12 31
15111 4 12 25
15222 5 12 24
15333 6 12 33
;

Accepted Solutions
Solution
‎06-20-2018 12:11 PM
Super User
Posts: 23,998

Re: Monthly Box Plot

The data step code you're trying to post is incomplete (in several posts now). 

 

Try adding a PROC SORT to see if sorting the data fixes the issue. You should also consider switching to SGPLOT - better control of your graphics and higher quality graphs in general.

 

proc sort data=have;
by month;
run;

proc boxplot data=have;
plot load*month;
run;

proc sgplot data=have;
vbox load / category=month;
run;

 


@matt23 wrote:

 Hi, I have a dataset with over 80,000 observations and I want to make a monthly box plot but get an error that the data isn't in order.

I want it to look like this:

Screen Shot 2018-06-20 at 11.39.18 AM.png

 

I used this code:

proc boxplot data=dataname;
plot Load*Month;
run;

And here's how some of the data looks like and goes on for years:

input load day month temperature
datalines:
12345 0 12 35
12456 1 12 33
12222 2 12 32
14532 3 12 31
15111 4 12 25
15222 5 12 24
15333 6 12 33
;

 

View solution in original post


All Replies
Super User
Posts: 13,926

Re: Monthly Box Plot

Since the values you display for the "day" axis are extremely unlikely given the "example data" , carefully edited to remove the data set name hiding the fact that you are plotting from a different data set where you have likely done some thing with the day an month variable we can't recreate what you have done.

 

Very likely you have created a character variable and then the "date" of 01Apr would be followed by 01Aug in sort order.

 

Hint: To have date related items sort in order then use actual DATE values. If you are looking for the spread of values for a given calendar day across years then assign the same year to all of the values and then use a date format to display the bit you want.

 

In your data step where you combined the day and month use:

 

Date = mdy(month, day, 1960);

format date date5. ; to show the date as ddMON

and then use the DATE variable for the x-axis variable.

 

Also is the "error" in the display or an actual SAS error message?

 

Solution
‎06-20-2018 12:11 PM
Super User
Posts: 23,998

Re: Monthly Box Plot

The data step code you're trying to post is incomplete (in several posts now). 

 

Try adding a PROC SORT to see if sorting the data fixes the issue. You should also consider switching to SGPLOT - better control of your graphics and higher quality graphs in general.

 

proc sort data=have;
by month;
run;

proc boxplot data=have;
plot load*month;
run;

proc sgplot data=have;
vbox load / category=month;
run;

 


@matt23 wrote:

 Hi, I have a dataset with over 80,000 observations and I want to make a monthly box plot but get an error that the data isn't in order.

I want it to look like this:

Screen Shot 2018-06-20 at 11.39.18 AM.png

 

I used this code:

proc boxplot data=dataname;
plot Load*Month;
run;

And here's how some of the data looks like and goes on for years:

input load day month temperature
datalines:
12345 0 12 35
12456 1 12 33
12222 2 12 32
14532 3 12 31
15111 4 12 25
15222 5 12 24
15333 6 12 33
;

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 76 views
  • 2 likes
  • 3 in conversation