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

Hi All:

 I'm producing a PDF with box plots and need an introductory page showing the figure illustrating box plot elements that's provide in the SAS documentation, near the bottom of the page, at: 

https://documentation.sas.com/?docsetId=grstatgraph&docsetTarget=p0vuh82v39fsasn1vqhzmhdl8y16.htm&do...

 

Could someone share their code for doing this, or give me a hint on accomplishing this in SAS 9.4?

 

Thanks.

Bill.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Bill_in_Toronto
Obsidian | Level 7

Thanks for the suggestions. I selected the image of box plot elements, saved it on my pc, and inserted the image on a separate page in my PDF file containing box plots, using the following approach:

 

ODS _ALL_ CLOSE;

OPTIONS NODATE NONUMBER;

ODS PDF FILE='c:\temp\testimage.pdf' STYLE=Dove PDFTOC=1 ;

ODS PROCLABEL "BoxPlotDescription";

ODS NOPROCTITLE ;

PROC GSLIDE

IFRAME='c:\temp\Box_Key_SG.png'

IMAGESTYLE = FIT

DESCRIPTION = 'Box Plot - Description';

TITLE1 'Box Plot: Description' J=r H=1 "&sysdate9";

RUN;

QUIT;

ODS PDF CLOSE;

View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ

There are several ways to do this. Are you looking for the basic box-and-whisker plot

or do you need something more complicated like a notched box plot? Do you also want to show the IQR and fences?

 

I'd use PROC MEANS of the OUTBOX= option in PROC BOXPLOT to get the numerical values for each feature. The graph will be a little tricky, but I'd try to use the HBOX statement to draw the box plot for real data and use the TEXT statement to add the explanatory text.

 

Quentin
Super User

I made a reference card like you're describing, several years back.  (With apologies to @Rick_SAS , for my use of the ancient rannor to simulate some data, at the time my eyes had not been opened to the beauty of the RAND function!).

 

My code is below:

 

data samp;
  retain 
    mean   70
    stddev 10
  ;

  do id=1 to 100; 
    Score=mean+stddev*rannor(3);
    if id=10 then score=25; 
    output;
  end;
run;

*hard code the values of statistics;
%let outlier=25;
%let min=44.49;
%let Q1=60.61;
%let mean=68.07;
%let median=70.49;
%let Q3=75.28;
%let max=89.17;

%macro DrawArrow(y=
                ,label=
                 );
        drawarrow x1=80 x2=70 y1=&y y2=&y /
          x1space=wallpercent
          x2space=wallpercent
          y1space=datavalue
          y2space=datavalue
        ;   
        drawtext "&label" /
          width=25
          x=82 y=&y
          xspace=wallpercent 
          yspace=datavalue
          anchor=left
        ;

%mend DrawArrow;

proc template;
  define statgraph MyBoxPlot;
    begingraph /
      border=false
    ;
      layout overlay /
        walldisplay=none
      ;      
        boxplot x=Class y=Score/
          spread=true
        ;
        %drawArrow(label=Outlier,y=&outlier)
        %drawArrow(label=Minimum (excluding outliers),y=&Min)
        %drawArrow(label=25th Percentile,y=&Q1)
        %drawArrow(label=Mean,y=&mean)
        %drawArrow(label=Median,y=&median)
        %drawArrow(label=75th Percentile,y=&Q3)
        %drawArrow(label=Maximum (excluding outliers),y=&Max)
      endlayout;
    endgraph;
  end;
run;


ods escapechar='^';
options nonumber;
ods listing close;
ods pdf file="%sysfunc(pathname(work))\BoxPlotReferenceCard.pdf" style=journal notoc;
title1 "Box Plot Reference Card";
footnote1 j=l "Source: SAS Graph Template Language Reference p. 215";
proc sgrender data=samp template="MyBoxPlot";
run;


ods pdf text="^{newline 5}";
ods pdf text="^{style [fontweight=bold]Outlier Definition (Gory Statistical Details)}";
ods pdf text="A value is an outlier if it is outside of the interval: [  P25 - 1.5*IQR  ,  P75 + 1.5*IQR  ] ";
ods pdf text="Where:";
ods pdf text="^{nbspace 4}P25 = 25th Percentile";
ods pdf text="^{nbspace 4}P75 = 75th Percentile";
ods pdf text="^{nbspace 4}IQR = Interquartile Range (75th Percentile - 25th Percentile)";
title1;
ods pdf close;
ods listing;
BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Bill_in_Toronto
Obsidian | Level 7

Thanks for the suggestions. I selected the image of box plot elements, saved it on my pc, and inserted the image on a separate page in my PDF file containing box plots, using the following approach:

 

ODS _ALL_ CLOSE;

OPTIONS NODATE NONUMBER;

ODS PDF FILE='c:\temp\testimage.pdf' STYLE=Dove PDFTOC=1 ;

ODS PROCLABEL "BoxPlotDescription";

ODS NOPROCTITLE ;

PROC GSLIDE

IFRAME='c:\temp\Box_Key_SG.png'

IMAGESTYLE = FIT

DESCRIPTION = 'Box Plot - Description';

TITLE1 'Box Plot: Description' J=r H=1 "&sysdate9";

RUN;

QUIT;

ODS PDF CLOSE;

Rick_SAS
SAS Super FREQ

I thought this was an interesting question, so I decided to ask myself a similar question: Given a set of data, can you draw the box plot and augment the box plot with a description of the important statistics and outliers for that data? In other words, can you solve the OP's problem in a data-driven way? 

 

My thoughts on the matter and some SAS code for how to create this image for any data set are available in the article

"Annotate features of a schematic box plot in SGPLOT."

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 1024 views
  • 4 likes
  • 4 in conversation