BookmarkSubscribeRSS Feed
lueryy2000
Calcite | Level 5

Dear all,

I want to get a boxplot for my data which has 20 boxes. I used axis statement to rename the value of x-axis tick marks to center1 tocenter20. I like all of them appear in the x-axis. But boxplot procedure only give center1, center3 till center19. Is it due to too many tick marks so theycan fit in the x-axis? And is there any way to solve this problem and let 20centers all show up in x-axis? Below is my data, the code to generate boxplot follows:

/***data***/

data sims;

call streaminit(16812);

array o_sfc osfc1-osfc20;

mu=200;

disp=5;

alpha= mu / (disp*(1-(1/disp)));

sig2 = 1/alpha;

pie = alpha / (mu + alpha);

do center = 1 to 20;

do over o_sfc;

o_sfc=RAND('NEGBINOMIAL',pie,alpha);

end;

output;

end; *replicate do loop;

run;

proc transpose data=sims (drop=disp mu alpha sig2 pie) out=sims2; by center; run;

proc means data=sims2 n mean var std cv min max; class center;var col1;title'Averages';run;

/***code***/

AXIS1 LABEL=(HEIGHT=1.8 'X-axis label' FONT='ARIAL' JUSTIFY=CENTER)

      ORDER=(1 to 20 by 1)

      VALUE=('Center 1' 'Center 2' 'Center 3' 'Center 4' 'Center 5' 'Center 6' 'Center 7' 'Center 8' 'Center 9' 'Center 10' 'Center 11' 'Center 12'

             'Center 13' 'Center 14' 'Center 15' 'Center 16' 'Center 17' 'Center 18' 'Center 19' 'Center 20' ANGLE=90)

      MAJOR=()

      ;

PROC BOXPLOT DATA=sims2;

    PLOT col1*center / BOXSTYLE=SCHEMATIC

                       HAXIS=AXIS1

                       ;

    INSETGROUP N MEAN (5.1) STDDEV (4.1);

RUN;

Thank you very much,

Lu

4 REPLIES 4
GraphGuy
Meteorite | Level 14

I'm not too familiar with "proc boxplot" (since it's not actually part of the SAS/Graph product), but from my little bit of experience I seem to recall that it doesn't support all of the features of the axis statement ... therefore maybe it doesn't support hardcoding the value text.

But, one work-around would be to use a user-defined format, such as the following (and, of course, there are several different ways to define a user-defined format) ...

AXIS1 LABEL=(HEIGHT=1.8 'X-axis label' FONT='ARIAL' JUSTIFY=CENTER)
      ORDER=(1 to 20 by 1);

proc format;
value myfmt
1 = "Center 1"
2 = "Center 2"
3 = "Center 3"
4 = "Center 4"
5 = "Center 5"
6 = "Center 6"
7 = "Center 7"
8 = "Center 8"
9 = "Center 9"
10 = "Center 10"
11 = "Center 11"
12 = "Center 12"
13 = "Center 13"
14 = "Center 14"
15 = "Center 15"
16 = "Center 16"
17 = "Center 17"
18 = "Center 18"
19 = "Center 19"
20 = "Center 20"
;
run;


PROC BOXPLOT DATA=sims2;
format center myfmt.;
    PLOT col1*center / BOXSTYLE=SCHEMATIC
                       HAXIS=AXIS1
                       ;
    INSETGROUP N MEAN (5.1) STDDEV (4.1);
RUN;

lueryy2000
Calcite | Level 5

Thanks for your answer. But your way still only gives odd centers. And I hope all centers could appear cause in my true data all 20 centers have different names. Any other suggestions? Thank you.

Lu

GraphGuy
Meteorite | Level 14

Oops - my bad!  I had been running in v9.3 DMS sas, which defaults to "ods graphics on", which is angling the x-axis values by defult (so that they fit).

Angling them manually will probably fix you up!...

AXIS1 LABEL=('X-axis label' JUSTIFY=CENTER) ORDER=(1 to 20 by 1) value=(angle=-45);

Or, here's a complete program that should hard-code everything to come out the way I'm seeing it:

%let name=box001;
filename odsout '.';

data sims;
call streaminit(16812);
array o_sfc osfc1-osfc20;
mu=200;
disp=5;
alpha= mu / (disp*(1-(1/disp)));
sig2 = 1/alpha;
pie = alpha / (mu + alpha);
do center = 1 to 20;
do over o_sfc;
o_sfc=RAND('NEGBINOMIAL',pie,alpha);
end;
output;
end; *replicate do loop;
run;

proc transpose data=sims (drop=disp mu alpha sig2 pie) out=sims2; by center; run;

proc means data=sims2 n mean var std cv min max; class center;var col1;title'Averages';run;

proc format;
value myfmt
1 = "Center 1"
2 = "Center 2"
3 = "Center 3"
4 = "Center 4"
5 = "Center 5"
6 = "Center 6"
7 = "Center 7"
8 = "Center 8"
9 = "Center 9"
10 = "Center 10"
11 = "Center 11"
12 = "Center 12"
13 = "Center 13"
14 = "Center 14"
15 = "Center 15"
16 = "Center 16"
17 = "Center 17"
18 = "Center 18"
19 = "Center 19"
20 = "Center 20"
;
run;

GOPTIONS DEVICE=png;
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm" style=sasweb;

goptions htext=1.8pct ftext='arial';

AXIS1 LABEL=('X-axis label' JUSTIFY=CENTER) ORDER=(1 to 20 by 1) value=(angle=-45);

PROC BOXPLOT DATA=sims2;
format center myfmt.;
    PLOT col1*center / BOXSTYLE=SCHEMATIC
                       HAXIS=AXIS1
                       des='' name="&name";
    INSETGROUP N MEAN (5.1) STDDEV (4.1);
RUN;

quit;
ODS HTML CLOSE;
ODS LISTING;

lueryy2000
Calcite | Level 5

This is exactly what I want. Thank you very much.

Lu

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
  • 3707 views
  • 3 likes
  • 2 in conversation