I have a scatter plot upon which I must overlay three other items:
1. Centroid value of X and Y (one value with marker)
2. A circle +/- 2.5 units of the centroid
3. A circle of +/-5.0 units of the centroid
What is the most effective way of doing this?
Which procedure do you plan on using?
Depending on procedure and version of SAS the second 2 are probably easiest with an annotate data set as you specify a a coordinate and radius for a circle. Which would require about 3 lines of code. Look at the %Circle macro in the annotate facility.
I originally planned to use SGPLOT - the software version I have is 9.2 TS2M3
GTL might be a good option if there's an easy way to draw a circle in it.
Simplest I can think of:
data junk;
x = 5; y=5;
run;
proc sgplot data=junk;
scatter x=x y=y /markerattrs=(symbol=circlefilled) name='yes';
scatter x=x y=y /markerattrs=(symbol=circle size=25mm) name='no';
scatter x=x y=y /markerattrs=(symbol=circle size=50mm) name='no2';
keylegend 'yes' /title='Legend';
run;
The size and units would likely change depending on the size of your final display and you may want to play with axis defintions to make it prettier.
If circles are not important, you can use XERRORUPPER/LOWER and YERRORUPPER/LOWER to show the +/-2.5 and +/-5.0 limits. You should need only two scatter overlays to show these limits, the first scatter can show the real point and the +/- 2.5 limits. The code will look something like this:
proc sgplot data=somedata nocycleattrs;
scatter x=x y=y / xerrorupper=xulimit50 xerrorlower=xllimit50 yerrorupper=yulimit50 yerrorlower=yllimit50 markerattrs=(size=0);
scatter x=x y=y / xerrorupper=xulimit25 xerrorlower=xllimit25 yerrorupper=yulimit25 yerrorlower=yllimit25;
run;
Dan,
Circles are kind of important since they are the companion to tables which show the actual counts
Any thoughts?
About how many scatter points are involved?
Probably about 50 per plot - I don't have SAS 9.3 will the 9.3 GTL still work?
Or perhaps proc gplot with a bubble plot with multiple requests overlayed.
If you're going to use the ODS Graphics systems to do this at SAS 9.2, the only way that comes to mind (warning: this is brute force) is to use ELLIPSEPARM statements in GTL. You would have to write a macro loop to generate an ELLIPSEPARM statement for each circle needed in the plot. Here is some pseudo-code for the idea:
proc template;
define statgraph myscatter;
begingraph;
layout overlay;
scatterplot x=x y=y;
%do %p=1 %to numberOfCircles;
ellipseparm semimajor=%unit semiminor=%unit slope=0 xorigin=%x yorigin=%y;
%end;
endlayout;
endgraph;
end;
run;
proc sgrender data=somedata template=myscatter; run;
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.