Data visualization with SAS programming

BOX Plot on a non discrete axis

Reply
Occasional Contributor
Posts: 19

BOX Plot on a non discrete axis

Is it possible to create box plots in ODS graphics on a linear scaled axis instead of a categorical? I want to have a time axis and a box per group, with jitter to be able to distiguish the boxes. Any help?
Super Contributor
Super Contributor
Posts: 3,174

Re: BOX Plot on a non discrete axis

Recommended Google advanced search argument:

boxplot linear axis site:sas.com


Scott Barry
SBBWorks, Inc.
Contributor
Posts: 36

Re: BOX Plot on a non discrete axis

I have been working on a similar problem. I am creating boxplots for the previous and current year, the past 12 months and the past 4 weeks. The methodology is to create groups and dategroups for each record. The value in the dategroup will be displayed on the axis. First step is to create three datasets for year, month and week. Key is to have the data in each to be sorted by the dategroup to chart properly. From the distinct group and dategrp values a format is created for charting. The program has some macro variables to color the boxplots differently for year, month and week. Read through it and hope it helps.


data group_year group_month group_week;
length dategrp $5. group $6.;
set dsnin;
/* current and previous 2 years fall into this group */
if year = year(&current_year_date) then dategrp='YTD';
else dategrp=put(year,4.);
group='Year';
output group_year;
/* last 12 full months - all samples fall into this group */
if os_date ge &prev12_month_date then
do;
if month = &current_month_date then dategrp='MTD';
else dategrp=put(month,monyy5.);
group='Month';
output group_month;
end;
/* last 4 weeks */
if week >= &prev4_week_date then
do;
dategrp=substr(put(week,yymmdd8.),4,5);
group='Week';
output group_week;
end;
label dategrp='Date';
run;

/* Join the data sets together and create the Date index file for the format create */
/* NOTE: THIS DATASET CONTAINS MORE DATA THAN THE ORIGINAL BECAUSE OF THE OVERLAP IN TIME */
data final
index(keep=dategrpindex dategrp group);
retain dategrpindex ;
set group_year
group_month
group_week;
/* Create a tag color set to group the data by Month, Week */
length boxcolor $8.;
if group='Year' then boxcolor="&mid_light_gray"; /* Blue */
else if group='Month' then boxcolor="&mid_light_blue"; /* Blue */
else /*week*/ boxcolor="&mid_light_rust"; /* rust */
/* Filter the data */
if dategrp ne lag(dategrp) then do;
dategrpindex+1;
output index;
end;
output final;
label dategrpindex='Date';
run;

/*------------------------------------------------------------------*/
/* Create the CNTLIN Dataset to load the format. USE for boxchart */
Data Load_Date_Scale_format;
retain type 'n';
set index end=endit;
by group notsorted;
fmtname='TimeAxis';
label=dategrp;
start=dategrpindex;
end=dategrpindex;
drop dategrp dategrpindex;
if endit then do;
call symputx('MaxDategrpindex', dategrpindex);
end;
output;
run;

/* Load the Format for the Time Axis Groups */
proc format /*fmtlib*/ cntlin=Load_Date_Scale_format;
run;

goptions reset=all ftitle=duplex htitle=4 ftext=simplex htext=3 device=sasprtc gunit=pct nodisplay;

/* Define Symbols and Axises */
axis1 order=(0 to 600 by 100) label=(angle=-90 rotate=90 h=2pct) origin = (10pct, 15pct) value=(h=2pct)
offset=(1pct, 1pct) length=70pct;
axis2 label=(h=2pct "Two Years, Last 12 Months, Last 4 Weeks")
order=( 1 to &Maxdategrpindex by 1) value=(h=1pct)
value=(h=1.5pct) offset=(2.5pct, 2.5pct);

/* Provide an BOX and WHISKER analysis across all crews */
title1 "Caster Tundish Turnaround Time";
footnote1 J=L h=1.5pct "Job ID: SO253_Tundish_Turnaround";
symbol1 v=dot i=none c=&mid_dark_blue;
symbol2 v=none;
proc shewhart data=final gout=work.charts;
boxchart variable*dategrpindex(group) /
cboxfill = ( boxcolor )
cboxes = CX000000
cinfill = CX999999
boxstyle = schematic
idsymbol = square
idcolor = purple
nolegend
vaxis=axis1
haxis=axis2
href= 2.5 14.5 /* Add vertical line to differenate Blocks */
turnhlabels
chref=black
lhref=1
vreflabpos=3
boxconnect
nolimits
blockpos=3
npanel=&Maxdategrpindex
cclip=red
clipsymbol=dot
clipfactor=4 /* This is 5 times the interQuartile Distance */
Des="All";
;
format turnaround 4. dategrpindex timeaxis.;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 149 views
  • 0 likes
  • 3 in conversation