Hi,
I would like to make a graph by 2 variables, create different colour labels for 3 different groups and be able to marke some specific observations (like outliers) in final graph.
So my code:
proc gplot data=mydata;
plot var2*var1=groupname/frame cframe=ligr
legend=legend1 vaxis=axis1 haxis=axis2;
run;
What I get what I need - values of those 2 variables by group names, but I can’t understand is there any possibility to mark in the graph which are those outlying observations?
I would appreciate if somebody of you could help.
Thank you,
Ieva
One way to selectively label certain outliers is to selectively assign text to a variable,
and then use that variable as the 'pointlabel' (assuming you're using a fairly recent
release of SAS)...
data foo; set sashelp.class;
if height>=67 then outlier_text=trim(left(height));
run;
symbol1 value=dot interpol=none pointlabel=("#outlier_text");
proc gplot data=foo;
plot height*weight;
run;
One way to selectively label certain outliers is to selectively assign text to a variable,
and then use that variable as the 'pointlabel' (assuming you're using a fairly recent
release of SAS)...
data foo; set sashelp.class;
if height>=67 then outlier_text=trim(left(height));
run;
symbol1 value=dot interpol=none pointlabel=("#outlier_text");
proc gplot data=foo;
plot height*weight;
run;
Thank you for suggestion!
I'm using SAS 9.1.3. When running your code I get labels for all observations. And when I try to change outlier_text to variable name (not height) also nothing is changing. Is my SAS version too old for this?
SAS 9.1.3 is over 7 years old but I tried both of those things in it just now, and they both work for me.
Is it possible you're using device=java or device=activex ?
They only have "partial support" of a lot of the features like pointlabel.
Ah, then it is because device=activex.
You can also mark outliers in a scatter plot by using ODS statistical graphics (the SGPLOT procedure). See http://blogs.sas.com/content/iml/2011/11/11/label-only-certain-observations-with-proc-sgplot/
Thank you! This seems as a good, simple aproach!
If you want to have more control over your graph, try the annotate facility:
proc sql;
create table anno as select '2' as xsys, '2' as ysys, height as y, weight as x,
name as text, 'label' as function,'"Arial"' as style, 'red' as color, '3' as position
from sashelp.class
having height not between avg(height)-2*std(height) and avg(height)+2*std(height) ;
quit;
ods html body='c:\temp\myGraph.html';
goptions dev=activex;
proc gplot data=sashelp.class;
plot height*weight / anno=anno;
run;quit;
ods html close;
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.