BookmarkSubscribeRSS Feed
Haris
Lapis Lazuli | Level 10

There does not seem to be a straightforward way to plot multiple box/bar groups with bars separated by decile lines. 

I have a dataset with several Measures and deciles for each measure.  Here's a simulated dataset:

data d;

  do Measure=1 to 5;

   do i=0 to 10;

     DecileVal = ranuni(0);

  output;

  end; end;

  drop i;

proc rank data=d out=d;

  by Measure;

  var DecileVal;

  ranks Decile;

proc sort data=d; by Measure Decile;

run;

So far the closest I get is this:

proc sgplot data=d;

  scatter x=Measure y=DecileVal / markerattrs=(symbol=plus);

run;

Still need:

- Change pluses into horizontal lines

- To add vertical boxes that start at a Min value and end at Max.

Can something like this be done in SGPlot?  I need to overlay odds ratios with CI over the bars?

Appreciate any help or pointers.

4 REPLIES 4
Haris
Lapis Lazuli | Level 10

Here's another SGPLOT routine that gives me something similar to what I am looking for but with estimated rather than literal percentiles, 50th, 25th, and 75th percentiles and whiskers at 0 and 100.

ballardw
Super User

Maybe not with SGPlot but you may find something at http://support.sas.com/sassamples/graphgallery/PROC_SGRENDER_Graph_Template_Language__GTL_.html that looks close to what you want. There are links to code to create each of the examples.

Haris
Lapis Lazuli | Level 10

Thanks for the suggestion, Ballardw.  Nothing there that looks like what I want but a good resource. Also, have done very limited amount of programming in TEMPLATE.  Useful skill but a steep learning curve.

I ended up transposing the Tall file into a wide one and using the following code:

proc sgplot data=df noautolegend;

  highlow x=Outcome low=D1 high=D11 /type=bar;

  highlow x=Outcome low=D2 high=D10 /type=bar;

  highlow x=Outcome low=D3 high=D9  /type=bar;

  highlow x=Outcome low=D4 high=D8  /type=bar;

  highlow x=Outcome low=D5 high=D7  /type=bar;

  highlow x=Outcome low=D6 high=D6  /type=bar;

  scatter x=Outcome y=OR / markerattrs=(color=black symbol=DiamondFilled size=15)

  yerrorlower=Lower yerrorupper=Upper errorbarattrs=(color=black thickness=2);

  xaxis labelattrs=(weight=bold size=14);

  yaxis label='Odds Ratio (95% CI)' labelattrs=(weight=bold size=14);

run;

Any feedback or suggestions for improvement is greatly appreciated.

Jay54
Meteorite | Level 14

You can overlay SCATTERPLOT on BOXPLOT using GTL. 

And yes, you can use a combination of HIGHLOW plots to simulate a box plot as I discuss in this blog post.  http://blogs.sas.com/content/graphicallyspeaking/2013/03/24/custom-box-plots/

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 1642 views
  • 3 likes
  • 3 in conversation