BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ieva
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

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

7 REPLIES 7
GraphGuy
Meteorite | Level 14

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;

ieva
Pyrite | Level 9

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

GraphGuy
Meteorite | Level 14

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.

ieva
Pyrite | Level 9

Ah, then it is because device=activex.

Rick_SAS
SAS Super FREQ

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/

ieva
Pyrite | Level 9

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

Alfredo
Fluorite | Level 6

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 4793 views
  • 4 likes
  • 4 in conversation