BookmarkSubscribeRSS Feed
asmits
Calcite | Level 5
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?
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Recommended Google advanced search argument:

boxplot linear axis site:sas.com


Scott Barry
SBBWorks, Inc.
barheat
Fluorite | Level 6
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;

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
  • 2 replies
  • 716 views
  • 0 likes
  • 3 in conversation