Data visualization with SAS programming

Splitting the format in proc boxplot

Reply
Contributor sfo
Contributor
Posts: 66

Splitting the format in proc boxplot

Hello,

I have a format which has a "," as a delimiter. For example:

proc format;

value cat   1 = "First, Second"

                  2 = "Third, Last";

run;

Is there a way I can split the text in two lines while using Proc BoxPlot? I am applying the format on the x-variable of the Box Plot which has values 1 and 2. So, I would like the x axis to split in two rows i.e. "First" and "Second" should display in two different rows.

Thanks

SAS Super FREQ
Posts: 889

Re: Splitting the format in proc boxplot

What version of SAS are you using?

Super User
Posts: 1,107

Re: Splitting the format in proc boxplot

Since you are working on sas9.2 , you can use split option in the axis statement of x-axis. something like below

axis1 label=none split=',';

proc boxplot data=have;

plot y*x / haxis=axis1;

run;

The split=',' we can mention the desired split character we have used. It will split the line to different rows where the split character is given.

Please let me know if this helped.

Thanks,

Jag

Thanks,
Jag
Contributor sfo
Contributor
Posts: 66

Re: Splitting the format in proc boxplot

Hi Jag,

I am using the below statements (as an example) but still the axis is not getting split.

proc format;

value cat   1 = "First, Name"

         2 = "Last, Name";

run;

goptions reset=legend;

goptions reset=all;

goptions display hby=2 fby=arial;

axis1 label=none

value = (h=2)

color  = black;

axis2 label=(f=arial h=1.5 "Categories")

split = ","

order = 1 to 2 by 1;

proc boxplot data =test;

format x cat.;

plot y*x /vaxis=axis1 haxis=axis2 ;

run;

Super User
Posts: 1,107

Re: Splitting the format in proc boxplot

could you please try to format the variable in the dataset test prior passing it into the boxplot procedure. i believe this might work

Thanks,
Jag
Super User
Posts: 1,107

Re: Splitting the format in proc boxplot

As Robert mentioned if the split option in the axis statement is not working then probably it is not available in proc boxplot.

Alternatively if you would still continue to use proc boxplot then you can try

axis1 label=(f=arial h=1.5 "Categories") value=(t=1 j=c "First" j=c "Name"

t=2 j=c "Second" j=c "Name" );

proc boxplot data=have;

plot y*x / haxis=axis1;

run;

Thanks,

Jag

Thanks,
Jag
SAS Super FREQ
Posts: 889

Re: Splitting the format in proc boxplot

If you have SAS 9.4, another possibility is to use the splitting abilities in the the SG procedures:

proc format;

value $cat "M"="First, Second"

           "F"="Third, Last"

;

proc sgplot data=sashelp.class;

format sex $cat.;

xaxis splitchar="," fitpolicy=splitalways;

vbox height / category=sex;

run;

proc sgplot data=sashelp.class;

format sex $cat.;

xaxis splitchar="," fitpolicy=splitalways splitcharnodrop;

vbox height / category=sex;

run;

Contributor sfo
Contributor
Posts: 66

Re: Splitting the format in proc boxplot

Thanks all for your reply.

SAS Employee
Posts: 967

Re: Splitting the format in proc boxplot

I don't think the axis "split=" option is supported in Proc Boxplot. It is supported in SAS/Graph Proc Gplot, in which you could use interpol=box. Here's a short example that demonstrates both of the above:

proc sort data=sashelp.class out=foo;

by sex;

run;

data foo; set foo;

if sex='F' then category=1;

if sex='M' then category=2;

run;

proc format;

value cat   1 = "First, Second"

                  2 = "Third, Last";

run;

axis1 split=',';

proc boxplot data=foo;

format category cat.;

plot height*category / haxis=axis1;

run;

symbol1 value=dot interpol=box;

axis1 split=',' offset=(8,8);

proc gplot data=foo;

format category cat.;

plot height*category / haxis=axis1;

run;

Ask a Question
Discussion stats
  • 8 replies
  • 769 views
  • 0 likes
  • 4 in conversation