BookmarkSubscribeRSS Feed
Manije72
Calcite | Level 5

Hi

I want to create a scatter plot showing correlation with a best fit line. When I use ellipse=0.2 0.3 in PROC CORR I find a scatter plot with circle best line. I want a straight best line like the picture I attached.

I want to create a scatter plot which shows r and P-value for correlation with a best fit line. Can you help me?

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Some of us (like me) never download attachments. Please show us the plot of interest by clicking on the "Insert Photos" icon and not via attaching a file.

 

Also, take a look at the ELLIPSE statement and the example here, if this is what you want, except no line, we can do this and add the line. 

--
Paige Miller
ballardw
Super User

Create output data from Proc Corr.

Use a data step to use that information to create a series of points for the line

Combine that data with the raw data

Use SGPLOT and overlay a Scatter plot of the raw data with a Series plot of the line points created.

Reeza
Super User

Plot:

proc sgplot data=sashelp.class;
reg x=height y=weight ;
run;

Values - need to get from PROC CORR and add in using INSET

 

Reeza
Super User

ods select none;
ods output parameterEstimates=pEst fitStatistics=fStats;
proc reg data=sashelp.class;
  model weight = height;
  output out=graphingData p=predicted;
run;

data _null_;
set fStats (obs=1);
call symputx('corr', put(sqrt(nValue2), 12.4));
run;

data _null_;
set pEst(obs=2);
call symputx('pvalue', put(probT, pvalue.));
run;
ods select all;
	
proc sgplot data=sashelp.class;
  reg x=height y=weight ;
  inset ("Correlation = " = "&corr."
          "P-Value =" = "&pvalue.");
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 3021 views
  • 3 likes
  • 4 in conversation