Hi all,
I am trying to create a box plot which looks like below.
(my variables are different. My y axis is 'time to diagnosis' and x axis is 'categories' (1-7) which are grouped by 'diagnosis source' (A/B))
I have tried following the SAS codes as shown in this blog (https://blogs.sas.com/content/graphicallyspeaking/2015/12/23/box-plot-with-stat-table-and-markers/ ).
But I am getting blanks ('.') in places where I should have my stats on top of the x axis.
Can anyone help me with this issue?
First, I saved the outputs of the sgplot and only kept the statistics I wanted (q1,q3,median).
Second, I transposed data so that each statistics had one column.
e.g. category group q1 q3 median
1 A num num num
1 B num num num
2 A num num num
2 B num num num
3 A num num num
3 B num num num etc.
Third, I merged this back onto my dataset (using the data set command)
Fourth, I ran the following code
proc sgplot data=merged;
label q1='Q1' q3='Q3' median='Median';
format q1 q3 median best4.;
vbox time_to_diagnosis / category=category group=diagnosis_source nooutliers grouporder=ascending name='a';
xaxistable q1 / x=category class=diagnosis_source classdisplay=cluster colorgroup=diagnosis_source location=inside;
xaxistable q3 / x=category class=diagnosis_source classdisplay=cluster colorgroup=diagnosis_source location=inside;
xaxistable median / x=category class=diagnosis_source classdisplay=cluster colorgroup=diagnosis_source location=inside;
xaxis display=(nolabel);
yaxis label="Time (days)" values=(0 to 1825 by 365);
keylegend 'a' / linelength=24;
run;
But I am getting blanks where I should have my stats...
I wonder if I have somehow messed up the dataset?
Please attach sample data and full program so we can run it to see what is happening. Also include SAS release number.
Hi Sanjay,
I attached a mock dataset for your information & I am using SAS 9.4.
Please let me know if you require anything else.
BW,
Dani
%let gpath=C:\;
ods html close;
%let w=5in;
%let h=2.5in;
%let dpi=200;
ods listing gpath="&gpath" image_dpi=&dpi;
/*--Read xlsx--*/
proc import datafile='C:\mockdataforboxplot.xlsx'
dbms=xlsx out=BoxTable replace;
getnames=yes;
run;
ods graphics / reset width=&w height=&h imagename='BoxTable';
title 'Time to DX by Category and Diagnosis Source';
proc sgplot data=boxtable noborder;
format q1 q3 median 6.1;
vbox time_to_dx / category=category group=diagnosis_source;
xaxistable q3 median q1 / x=category class=diagnosis_source
location=inside classdisplay=cluster valueattrs=(size=8 weight=normal);
yaxis display=(noline noticks) grid;
xaxis display=(nolabel);
run;
It is not complaining about the size of the data, but about the size of the output graph image (30,000px x 15,000px). Check your WIDTH, HEIGHT and IMAGE_DPI settings. You have not included that information in your post.
Dear Sanjay,
The codes worked after adding these codes at the beginning:
ods listing close;
ods listing;
However, the the values are still empty....
I'm really not sure what the problem is...
It would appear your data for Q1, Q3 and median are missing. As I have said before, please attach your full code with sample data.
Hi Sanjay,
I apologise for the inconvenience, but it is very difficult for me to attach the exact SAS codes or sample data as my analyses are being done on a secure/private network. So my data and the SAS programme are all on a different network which I cannot access from here. The computer I am using at the moment does not even have SAS!
But the mockdata is a similar format as my real data, and I have used the same codes as you have mentioned. I apologise for this inconvenience, and will try to figure out what may be wrong at my end.
I understand your constraints. You do not need to upload the "real" confidential data. Any small sample will do as long as it works with your code. It is even better if you can use one of the SAS supplied data sets to demonstrate the problem (like my example). This will make it easier for other users to help out. Just guessing at what may be wrong based on small snippets of your code or data types may not be productive.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.