BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
matt23
Quartz | Level 8

 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
;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

2 REPLIES 2
ballardw
Super User

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?

 

Reeza
Super User

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
;

 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 926 views
  • 2 likes
  • 3 in conversation