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;
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1788 views
  • 4 likes
  • 4 in conversation