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

I'm pretty new to using SAS for creating graphs and charts. I copied some programming from a SAS program I found online and it did help create a graph that I like, but the names overlap. I was wondering if there was a way to create something that wouldn't overlap? I have provided the code and attached the chart. 

 

proc boxplot data=Work.FruitOutliers;

   plot ErrorPer*DateofReport /

           boxstyle=schematicid

           nohlabel;

   id Outliers;

   label ErrorPer = 'Errors';

run;

goptions reset=symbol;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Should be doable with GTL. This is an example from the documentation and you should have the SASHELP.CARS data set it uses.

proc template;
  define statgraph boxplot;
    begingraph;
      entrytitle "City Mileage for Vehicle Types";
      layout overlay /
        xaxisopts=(offsetmin=0.1 offsetmax=0.1);
        boxplot y=mpg_city x=type /
          datalabel=make spread=true;
      endlayout;
    endgraph;
  end;
run;

proc sgrender data=sashelp.cars template=boxplot;
  label type="Vehicle Type";
run;

You would obviously change the text for Entrytitle (or remove entirely) and specify your variables for X= and y=. Datalabel=Make tells SAS to use the value the Make variable as a label for the outliers. The Spread=True horizontally spreads values that are the same on the Y axis so you can see separate markers to the labels may have issues if you have lots of these. You would also change the Sgrender code to reference your data set and likely the Label of the X variable. It would use any default label for your X and Y variables on the axis labels.

 

The xaxisopts used provide some space between the boxes on the left and right limits of the graph. Sometimes the defaults will crowd things up to the limits of the graph area.

View solution in original post

6 REPLIES 6
Reeza
Super User
I would highly recommend using SGPLOT and the VBOX or HBOX statements instead of BOXPLOT.

BOXPLOT is pretty old as a procedure though SAS maintains backwards compatibility.

Some examples are here:
https://blogs.sas.com/content/graphicallyspeaking/2016/12/08/getting-started-sgplot-part-3-vbox/
brookeewhite1
Quartz | Level 8

Reeza,

 

I work with aylee214 and we are working on this chart together.  We would be glad to try using SGPLOT, but after looking at the linked examples, we were not sure whether there is a way to add labels? For example, in this picture, the various fruit names are shown (which we like), but we want to somehow make it cleaner so that the names don't overlap. Would a VBOX or HBOX statement allow us to do that?  Thanks for your help, we appreciate it!

 

Capture.PNG

ballardw
Super User

Should be doable with GTL. This is an example from the documentation and you should have the SASHELP.CARS data set it uses.

proc template;
  define statgraph boxplot;
    begingraph;
      entrytitle "City Mileage for Vehicle Types";
      layout overlay /
        xaxisopts=(offsetmin=0.1 offsetmax=0.1);
        boxplot y=mpg_city x=type /
          datalabel=make spread=true;
      endlayout;
    endgraph;
  end;
run;

proc sgrender data=sashelp.cars template=boxplot;
  label type="Vehicle Type";
run;

You would obviously change the text for Entrytitle (or remove entirely) and specify your variables for X= and y=. Datalabel=Make tells SAS to use the value the Make variable as a label for the outliers. The Spread=True horizontally spreads values that are the same on the Y axis so you can see separate markers to the labels may have issues if you have lots of these. You would also change the Sgrender code to reference your data set and likely the Label of the X variable. It would use any default label for your X and Y variables on the axis labels.

 

The xaxisopts used provide some space between the boxes on the left and right limits of the graph. Sometimes the defaults will crowd things up to the limits of the graph area.

brookeewhite1
Quartz | Level 8

ballardw,

 

Thank you!  Once we tried your code as a template and substituted our data it worked like a charm and looks so much better than before!

 

 

aylee214
Calcite | Level 5

Thank you, thank you!!! 

Reeza
Super User
You can pair vbox with data label options or even addd your own text statements so IMO it gives you the most flexibility. And if you can’t figure it out via SGPLOT, then it can generate the GTL code via TMPLOUT option and you can modify that.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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