BookmarkSubscribeRSS Feed
marisa_jenkins
Fluorite | Level 6

HI all

I know you can add a refline in PROC SGPLOT but can you do it in PROC SGSCATTER?

 

e.g. This is the code we would use to get a refline at Y=0 using PROC SGPLOT but we are teaching a course that primarily uses SGSCATTER as has the ability to produce multiple scatterplots in one PROC and keen to just stick with that.

 

PROC SGPLOT DATA=dataset;
   SCATTER X= xvar Y= yvar;
   LOESS X= xvar Y= yvar;
   REFLINE 0;
RUN;

 

Thank you Marisa

5 REPLIES 5
Reeza
Super User
Not AFAIK but you can add a regression or loess line.

Sgcatter does have tmplout on the PROC statement so you can get the GTL code and modify that.

Or switch to SGPANEL?

marisa_jenkins
Fluorite | Level 6

Thank you Reeza

Yes we can add a LOESS line in PROC SGSCATTER but are looking for a ref line at Y = 0.

We currently use a mix of PROC GPLOT and PROC SGSCATTER but are hoping to just use one and not introduce another to be consistent with out other units.

Marisa

PGStats
Opal | Level 21

Could also be done with SG annotation.

PG
marisa_jenkins
Fluorite | Level 6

Thank you PG

We are keen to keep with PROC SGSCATTER as that is what is used throughout our course.

Marisa

PGStats
Opal | Level 21

SGSCATTER is not a good choice as a general purpose graphing procedure, if I may say so. Here is how to draw reference lines with annotation in SGSCATTER:

 

data reflines;
retain drawspace "layoutpercent" linecolor "blue";
input function $ x1 y1 x2 y2;
datalines;
line 11 55.5 53.5 55.5 
line 56 55.5 99   55.5
;

proc sgscatter data=sashelp.class sganno=reflines;
compare x=(age height) y=weight / loess=(degree=2);
run;

SGScatter8.png

 

 

Positioning the reference lines was by trial and error as you cannot tie their positions to data values.  

PG

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1590 views
  • 0 likes
  • 3 in conversation