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
What version of SAS are you using?
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
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;
could you please try to format the variable in the dataset test prior passing it into the boxplot procedure. i believe this might work
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
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;
Thanks all for your reply.
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.