BookmarkSubscribeRSS Feed
Petersi
Calcite | Level 5
With the ODS graphics in PROC ANOVA, can you modify the order of the class variable on the x-axis? I am comparing averages across days of the workweek, and it works fine if I use the numeric value of the day, however when I format the weekday it puts it in alphabetical order (FRI, MON, THU, etc.). Using ORDER=INTERNAL does not seem to work.
1 REPLY 1
Cynthia_sas
SAS Super FREQ
The way that ANOVA works is to use the formatted value. You could try formatting like this:
1-S
2-M
3-T
4-W
5-R
6-F
7-S
or something similar to get the number with the day value (either all or part of the day).

OR, in SAS 9.1.3, you could change the graph template to put in a simulated legend. The code below shows both methods on some data.
cynthia

[pre]
*** the code;
** Method 1: Use a Number in the format to keep order;
ods path sashelp.tmplmst(read) ;

data Clover2;
input Strain $ Nitrogen Day @@;
return;
datalines;
3DOK1 19.4 1 3DOK1 32.6 1 3DOK1 27.0 1 3DOK1 32.1 1 3DOK1 33.0 1
3DOK5 17.7 2 3DOK5 24.8 2 3DOK5 27.9 2 3DOK5 25.2 2 3DOK5 24.3 2
3DOK4 17.0 3 3DOK4 19.4 3 3DOK4 9.1 3 3DOK4 11.9 3 3DOK4 15.8 3
3DOK7 20.7 4 3DOK7 21.0 4 3DOK7 20.5 4 3DOK7 18.8 4 3DOK7 18.6 4
3DOK13 14.3 5 3DOK13 14.4 5 3DOK13 11.8 5 3DOK13 11.6 5 3DOK13 14.2 5
COMPOS 17.3 6 COMPOS 19.4 6 COMPOS 19.1 6 COMPOS 16.9 6 COMPOS 20.8 6
;
run;

proc format;
value dayf 1 = '1-SUN'
2 = '2-MON'
3 = '3-TUE'
4 = '4-WED'
5 = '5-THU'
6 = '6-FRI'
7 = '7-SAT';
run;

ods html path='c:\temp' (url=none)
gpath='c:\temp' (url=none)
file='anova_origtemp.html'
style=analysis;
ods select boxplot;
ods graphics on /imagefmt=staticmap;
title '1) Original template and format';
proc anova data = Clover2;
class Day;
model Nitrogen = Day;
format day dayf.;
run;
quit;

ods graphics off;
ods html close;


** Method 2: change the template to put in a simulated legend;
ods path work.temp(update) sashelp.tmplmst(read) ;

proc template;
define statgraph Stat.GLM.Graphics.BoxPlot;
dynamic _DEPVAR _CLASSVAR _GROUPDFBY;
layout gridded;
layout lattice / rows=1 columns=1;
Sidebar / Align=top;
layout Overlay / padbottom=3;
layout gridded / columns=4 valign=top;
entrytitle "Distribution of ";
entrytitle _DEPVAR;
entrytitle " by ";
entrytitle _CLASSVAR;
endlayout;
EndLayout;
EndSidebar;
layout overlay / ygrid=true;
boxplot y=_DEPEN x=_GROUPDFBY / datalabel=_DOBS labelfar=on
notches=off connect=none mediansymbol=line meansymbol=diamond
markers=on markersymbol=circle fill=on capshape=serif;
endlayout;
endlayout;
layout gridded /border=yes rows=1;
entry "1=Sun 2=Mon 3=Tue 4=Wed 5=Thu 6=Fri 7=Sat"
/foreground=purple
fontweight=bold
fontsize=12pt;
endlayout;
endlayout;
end;
run;

ods html path='c:\temp' (url=none)
gpath='c:\temp' (url=none)
file='anova_newtemp.html'
style=analysis;
ods select boxplot;
ods graphics on /imagefmt=staticmap;
title '2) New template and Day numbers and Legend';

proc anova data = Clover2;
class Day;
model Nitrogen = Day;
run;
quit;

ods graphics off;
ods html close;

[/pre]

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
  • 1 reply
  • 1165 views
  • 0 likes
  • 2 in conversation