BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
plf515
Lapis Lazuli | Level 10

Hello

 

Using SAS 9.4 TS 1M4 on Windows

 

I have a data set that contains variables _NODE_ and mpg, e.g

 

 

Obs MPG _Node_ _Leaf_ P_MPG1234
18.09214.0119
15.09214.0119
18.09214.0119
16.09214.0119

 

 

I would like to make a box plot by node but add a box for all the nodes.

 

I tried

proc sgplot data = tree.mpgout;
 vbox mpg /group = _node_;
 vbox mpg/boxwidth= 0.1;
run;

but this put the second box in the middle, blotting out other boxes.  I didn't see a way to set the location of the boxes.

 

How can I make this plot? THanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

To get all of this into a single graph probably the easiest is to modify your data so that you have your existing data plus a duplicate that has a _node_ value to indicate the "whole data".

That code would look something like:

data tree.vboxplot;
   set tree.mpgout 
       tree.mpgout(in=in2)
   ;
   if in2 then _node_='Total';
run;

You have no indication whether _node_ is numeric or character so I can't provide anything guaranteed to work but that should give you an idea. If you want the whole data on the left set a node value smaller or earlier in the sort order, on the right set a value larger or after the others.

 

The plot code would then use the new set and drop the second vbox statement:

proc sgplot data = tree.vboxplot;
 vbox mpg /group = _node_;
run;

 

View solution in original post

1 REPLY 1
ballardw
Super User

To get all of this into a single graph probably the easiest is to modify your data so that you have your existing data plus a duplicate that has a _node_ value to indicate the "whole data".

That code would look something like:

data tree.vboxplot;
   set tree.mpgout 
       tree.mpgout(in=in2)
   ;
   if in2 then _node_='Total';
run;

You have no indication whether _node_ is numeric or character so I can't provide anything guaranteed to work but that should give you an idea. If you want the whole data on the left set a node value smaller or earlier in the sort order, on the right set a value larger or after the others.

 

The plot code would then use the new set and drop the second vbox statement:

proc sgplot data = tree.vboxplot;
 vbox mpg /group = _node_;
run;

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 632 views
  • 1 like
  • 2 in conversation