BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Anv_SAS
Calcite | Level 5

Hi Team,

 

I'm trying to create BOXPLOT, as per below mock, using styles.rtf.

 

Anv_SAS_0-1679317166340.png

 

But I'm getting output as below.

Anv_SAS_1-1679317284567.png

I'm unable to restrict FILLPATTERN and unable to get DASHED lines for entire box.

 

Also, I'm restricted to use STYLE.RTF only.

 

I'm using below TEMPLATE code for creating BOXPLOT.

 

Anv_SAS_2-1679318194140.png

Anv_SAS_3-1679318235572.png

 

Please can you help in fixing the above issue.

 

Regards,

Anvesh

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Your question is really not easy.

Here is an example.

Hope you can get the graph you want by refer to the following code.

Good Luck.

[Edited]

data have;
 set sashelp.heart(keep=status sex weight);
run;

ods select none;
ods output sgplot=sgplot;
proc sgplot data=have;
vbox weight/category=status group=sex nooutliers ;
run;
ods select all;
data want;
 set sgplot;
 if BOX_WEIGHT_X_STATUS_GROUP_SE__ST in ('MIN' 'Q1' 'MEDIAN' 'Q3' 'MAX' 'MEAN') ;
run;
proc sort data=want;by BOX_WEIGHT_X_STATUS_GROUP_SE___X BOX_WEIGHT_X_STATUS_GROUP_SE__GP;run;
proc transpose data=want out=want2;
by BOX_WEIGHT_X_STATUS_GROUP_SE___X BOX_WEIGHT_X_STATUS_GROUP_SE__GP;
var BOX_WEIGHT_X_STATUS_GROUP_SE___Y;
id BOX_WEIGHT_X_STATUS_GROUP_SE__ST;
run;
data want2;
 set want2;
 l_mean=mean-5;
 h_mean=mean+5;
run;


ods graphics/ATTRPRIORITY=none;
proc sgplot data=want2;
styleattrs DATALINEPATTERNS=(solid shortdash) ;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=max low=min /
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=q3 low=q1/type=bar barwidth=0.5 nooutline
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster fillattrs=(color=white);

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=q3 low=q1/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=median low=median/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=min low=min/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=max low=max/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=mean low=mean/type=bar barwidth=0.2
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=h_mean low=l_mean/
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster ;

run;


Ksharp_0-1679665238023.png

 

View solution in original post

9 REPLIES 9
Hao_Luo
SAS Employee

Try to remove "fillpattern" from the display= option, and add "pattern=3" into outlineattrs=, whiskerattrs= and medianattrs= options.

Anv_SAS
Calcite | Level 5
But my requirement is to also represent treatment group by different line pattern (1st with solid line, 2nd treatment with dotted lines). How we can add 2 linepatterns in outlineattrs=, whiskerattrs= and medianattrs= options in boxplot.
Ksharp
Super User

Your question is really not easy.

Here is an example.

Hope you can get the graph you want by refer to the following code.

Good Luck.

[Edited]

data have;
 set sashelp.heart(keep=status sex weight);
run;

ods select none;
ods output sgplot=sgplot;
proc sgplot data=have;
vbox weight/category=status group=sex nooutliers ;
run;
ods select all;
data want;
 set sgplot;
 if BOX_WEIGHT_X_STATUS_GROUP_SE__ST in ('MIN' 'Q1' 'MEDIAN' 'Q3' 'MAX' 'MEAN') ;
run;
proc sort data=want;by BOX_WEIGHT_X_STATUS_GROUP_SE___X BOX_WEIGHT_X_STATUS_GROUP_SE__GP;run;
proc transpose data=want out=want2;
by BOX_WEIGHT_X_STATUS_GROUP_SE___X BOX_WEIGHT_X_STATUS_GROUP_SE__GP;
var BOX_WEIGHT_X_STATUS_GROUP_SE___Y;
id BOX_WEIGHT_X_STATUS_GROUP_SE__ST;
run;
data want2;
 set want2;
 l_mean=mean-5;
 h_mean=mean+5;
run;


ods graphics/ATTRPRIORITY=none;
proc sgplot data=want2;
styleattrs DATALINEPATTERNS=(solid shortdash) ;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=max low=min /
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=q3 low=q1/type=bar barwidth=0.5 nooutline
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster fillattrs=(color=white);

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=q3 low=q1/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=median low=median/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=min low=min/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=max low=max/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=mean low=mean/type=bar barwidth=0.2
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=h_mean low=l_mean/
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster ;

run;


Ksharp_0-1679665238023.png

 

Anv_SAS
Calcite | Level 5

Hi Ksharp,

 

Thanks you a lot. The solution you shared suffice the mock requirements. But it is not producing all the stats (MIN, MAX, MEAN, MEDIAN, N, DATAMAX, DATAMIN, OUTLIERS etc) produced by BOXPLOT in graph output.

Ksharp
Super User
Can you post a picture to explain what graph you want to see?
Anv_SAS
Calcite | Level 5

Hi Ksharp,

 

Please find the screenshot of the output I needed, as requested.

 

 

Anv_SAS_0-1679752298183.png

Ksharp
Super User

So what is different between yours and mine?

The max min value in my graph is not real max min of value.

Check the following picture to see what box line stand for.

 

Ksharp_0-1679823042705.png

 

 

Anv_SAS
Calcite | Level 5

Thank You Ksharp.

 

We are getting all stats, except outliers. However, I hope in this model (solid and dashed), we cannot get outliers differentiated.

 

Your response suffice mock requirements, as shown in figure.

 

Thanks a lot.

Ksharp
Super User

OK. You want outliers as SAS did ? No problem.

 

data have;
 set sashelp.heart(keep=status sex weight);
run;

ods select none;
ods output sgplot=sgplot;
proc sgplot data=have;
vbox weight/category=status group=sex  ;
run;
ods select all;
data stat outliers;
 set sgplot;
 if BOX_WEIGHT_X_STATUS_GROUP_SE__ST in ('MIN' 'Q1' 'MEDIAN' 'Q3' 'MAX' 'MEAN') then output stat;
 if find(BOX_WEIGHT_X_STATUS_GROUP_SE__ST,'OUTLIER') then output outliers;
run;
proc sort data=stat;by BOX_WEIGHT_X_STATUS_GROUP_SE___X BOX_WEIGHT_X_STATUS_GROUP_SE__GP;run;
proc transpose data=stat out=stat2;
by BOX_WEIGHT_X_STATUS_GROUP_SE___X BOX_WEIGHT_X_STATUS_GROUP_SE__GP;
var BOX_WEIGHT_X_STATUS_GROUP_SE___Y;
id BOX_WEIGHT_X_STATUS_GROUP_SE__ST;
run;
data stat2;
 set stat2;
 l_mean=mean-5;
 h_mean=mean+5;
run;
data want;
 set stat2 outliers;
run;

ods graphics/ATTRPRIORITY=none;
proc sgplot data=want;
styleattrs DATALINEPATTERNS=(solid shortdash) ;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=max low=min /
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=q3 low=q1/type=bar barwidth=0.5 nooutline
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster fillattrs=(color=white);

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=q3 low=q1/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=median low=median/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=min low=min/type=bar barwidth=0.3
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=max low=max/type=bar barwidth=0.3
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=mean low=mean/type=bar barwidth=0.15
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;

highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=h_mean low=l_mean/
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster ;

scatter x=BOX_WEIGHT_X_STATUS_GROUP_SE___X y=BOX_WEIGHT_X_STATUS_GROUP_SE___Y/
group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster markerattrs=(color=black);
run;

Ksharp_0-1679918011703.png

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 9 replies
  • 828 views
  • 0 likes
  • 3 in conversation