BookmarkSubscribeRSS Feed
Dani08
Obsidian | Level 7

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?

 

 

Image result for sas sgplot boxplot side by side

 

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?

        

9 REPLIES 9
Jay54
Meteorite | Level 14

Please attach sample data and full program so we can run it to see what is happening.  Also include SAS release number.

Dani08
Obsidian | Level 7

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

Jay54
Meteorite | Level 14

 

%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;
 

 

BoxTable.png

Dani08
Obsidian | Level 7
Dear Sanjay,

Thank you very much!
I am sure this works, as can seen from the picture.
When I used the code for my dataset, I get the following error message:

Warning: a very large output size of (30000, 15000) is in effect. This could make Java VM run out of memory and result in some JAVA exceptions. You should reduce output size or DPI settings.

I have tried reducing dpi settings, but not sure how to reduce output size. My actual dataset is much larger than the mock one I attached, but I'm not sure if that is the problem here.
Jay54
Meteorite | Level 14

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.

Dani08
Obsidian | Level 7

Dear Sanjay,

The codes worked after adding these codes at the beginning:

ods listing close;
ods listing;

However, the the values are still empty....

box.jpg

I'm really not sure what the problem is...

 

Jay54
Meteorite | Level 14

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.

Dani08
Obsidian | Level 7

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.

Jay54
Meteorite | Level 14

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 6749 views
  • 0 likes
  • 2 in conversation