Data visualization with SAS programming

Looking for advice/ideas for box plots to use as stored processes in WRS

Reply
Contributor
Posts: 40

Looking for advice/ideas for box plots to use as stored processes in WRS

Hi,

I'm very new to boxplots and stored processes, ok with SAS base programming (using 9.2) and ok with WRS.

We have an idea to show data as box plots in WRS, I understand this can be done via stored processes. I would need to show 2 boxplots overlaid, for the following type of data:

I have 152 areas that make up Country data and I want to show the spread of data for the Country, but this data is also split into comparator groups which comprise of 18 of the areas in each group.

In WRS we will have a report for each area and I want to have a horizontal box plot with the data for the whole Country and the data for the comparator group for that area overlaid. I also want to add a marker to show the value for that council too.

What I need to work out is which of the proceedures in SAS will be best for this - if it's possible to do, how do I save it as a stored process and what listing menthod should I use? Any help in these areas would save me a great deal of trial and error time (as I'm a bit up against it timewise) and would be gratefully received.

We do show other data using the same set up (i.e. Area, it's comparator group and country data) in bar charts quite sucessfully in WRS

Thanks
Nicola
SAS Employee
Posts: 980

Re: Looking for advice/ideas for box plots to use as stored processes in WRS

Per the traditional SAS boxplots (either using proc gplot with the box interpolation, or using proc boxplot), you might could overlay 2 of them using "proc greplay". You would want to make sure that the axes and all the text (titles, footnotes, axis text, etc) are exactly the same in both overlaid plots, so they will overlay in the exact same location - the only thing you'll want to be "different" is the boxplot itself).

Are you certain you want the 2 boxplots overlaid, rather than side-by-side?
Contributor
Posts: 40

Re: Looking for advice/ideas for box plots to use as stored processes in WRS

Yes, the preference would be overlaid so that County, Comparator group and the value for the one Area can all be displayed together on one set of axes. Though if this proves too difficult then one on above the over could work just as well.

I've seen that you can create overlaid boxplots using proc template and begingraph, with layout = overlay, but this produces vertical plots. I've also seen that you can produce horizontal plots using ODS graphics and specifying the boxstyle as horizontal, but I haven't worked out how to do both horizontal and overlaid together yet. I'll have a look at proc greplay.

Thanks
SAS Super FREQ
Posts: 925

Re: Looking for advice/ideas for box plots to use as stored processes in WRS

Hey Nicola,

This should be doable using ODS Graphics. Are you trying to create one graph per area using a BY-group or are you trying to put them in a panel?

Thanks!
Dan
Contributor
Posts: 40

Re: Looking for advice/ideas for box plots to use as stored processes in WRS

Hi Dan, thanks for your reply.

Yes, I will be creating 1 graph per Area, I'm hoping I can save it as a stored process so that I can add it to WRS ..... once I get the code to produce the plot I want working.

The report has Area as a group break and so I'm hoping to set it up so the WRS will feed the stored process with the Area parameter and then whichever Area is selected in the report it will contain a horizontal box plot with the values for England and then the values for comparator Areas on top of this and a marker to show where the Area value for that given Area lies. (this does seem like a tall order to me, but if SAS can do it then great!)

That's the vision anyway, I'm still at the stage of getting the base code to work in EG, I know I still need to think about my data structure and get that set up the right way to feed the graphs - just struggling for time at the minute

Nicola
SAS Employee
Posts: 11

Re: Looking for advice/ideas for box plots to use as stored processes in WRS

As Dan mentions, this is doable using the sgpanel procedure. As long as your dataset has a group variable for each value of comparator, you can then use that variable on the panelby statement.
SAS Super FREQ
Posts: 925

Re: Looking for advice/ideas for box plots to use as stored processes in WRS

Hey Nicola,

I put together this little example that seems to line up with your needs. Try it out and see what you think.

Thanks!
Dan

[pre]
/* The value you want to compare against the whole */
%let name=James;

/* get the column for the whole class */
data total_height;
set sashelp.class;
keep height all_id;
rename height=total_height;
length all_id $ 12;
all_id = "Entire class";
run;

/* Get the column for males only */
data male_height;
set sashelp.class (where=(sex="M"));
keep height male_id;
rename height=male_height;
length male_id $ 9;
male_id = "Male-only";
run;

/* Get the value to compare */
data actual_height;
set sashelp.class (where=(name="&name"));
keep height name;
rename height=actual_height;
run;

/* Merge them into the same dataset */
data plot_data;
merge total_height male_height actual_height;
run;

/* Graph template */
proc template;
define statgraph boxplot;
begingraph;
entrytitle "Box plot for &name";
layout overlay / yaxisopts=(type=discrete label="Categories") xaxisopts=(griddisplay=on label="Height");
scatterplot x=actual_height y=name;
boxplot y=male_height x=male_id / fillattrs=GraphData2 orient=horizontal;
boxplot y=total_height x=all_id/ fillattrs=GraphData1 orient=horizontal;
endlayout;
endgraph;
end;
run;

/* Run it! */
proc sgrender data=plot_data template=boxplot; run;
[/pre]
Contributor
Posts: 40

Re: Looking for advice/ideas for box plots to use as stored processes in WRS

Hey Thanks Dan,

I will have a play and get back to you!

Nicola
Contributor
Posts: 40

Re: Looking for advice/ideas for box plots to use as stored processes in WRS

Dan,

This is almost perfect! the only let down is it doesn't overlay the bars, I think it's because the y data are seperate variables in the plot_data data set.

Playing about with it, I got this to look like I want

/* Graph template */
proc template;
define statgraph boxplot2;
begingraph;
entrytitle "Box plot for &name";
layout overlay ;
boxplot y=weight x= sex/ datatransparency=0.5 fillattrs=GraphData2 orient=horizontal;
boxplot y=height x= sex/ datatransparency=0.5 fillattrs=GraphData1 orient=horizontal xaxis = x2;
endlayout;
endgraph;
end;
run;

proc sgrender data=sashelp.class template=boxplot2; run;

I'm just not sure yet whether I can get this code to work with my data. Will have a think and a further play with my actual data this time, when I get chance during this week.

However, if I decide that I can settle for graphs one above the over, your code just about perfect for my needs.

I am very grateful though, you've defintately given me inspiration that it could work they way I want.

Thank you
Nicola
Contributor
Posts: 40

Re: Looking for advice/ideas for box plots to use as stored processes in WRS

Hi Dan,

a quick update - I've got it working perfectly, I'm so grateful for your suggestion, the key thing that made a difference was the orient option in the boxplot statement for proc template, the rest was just getting my data into the right structure. The base code works a treat and I've had loads of fun playing with all the attribute options available in proc template to get it looking just how I want.

Now, just need to save it as a stored process and see if it works in WRS - look out for me scratching my head in the other forums ;-)

Nicola
Ask a Question
Discussion stats
  • 9 replies
  • 354 views
  • 0 likes
  • 4 in conversation