Data visualization with SAS programming

Marking outlier names on graph

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 82
Accepted Solution

Marking outlier names on graph

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


Accepted Solutions
Solution
‎11-02-2011 09:27 AM
SAS Employee
Posts: 980

Marking outlier names on graph

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;

View solution in original post


All Replies
Solution
‎11-02-2011 09:27 AM
SAS Employee
Posts: 980

Marking outlier names on graph

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;

Frequent Contributor
Posts: 82

Marking outlier names on graph

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? Smiley Happy

SAS Employee
Posts: 980

Marking outlier names on graph

SAS 9.1.3 is over 7 years old Smiley Happy 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.

Frequent Contributor
Posts: 82

Marking outlier names on graph

Ah, then it is because device=activex.

SAS Super FREQ
Posts: 3,630

Marking outlier names on graph

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/

Frequent Contributor
Posts: 82

Marking outlier names on graph

Thank you! This seems as a good, simple aproach!

Occasional Contributor
Posts: 8

Marking outlier names on graph

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;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 1209 views
  • 3 likes
  • 4 in conversation