This sample uses the REG procedure to obtain the parameter estimates and the descriptive statistics for a simple linear regression model. The SGPLOT procedure is used to display the regression equation and descriptive statistics. The INSET statements display the regression equation and descriptive statistics on the graph. Modify the POSITION= option in the INSET statement in order to display the regression and descriptive statistics in different locations on the graph. You must have SAS/STAT® software in order to run PROC REG.
To access the sample program, click the Full Code tab.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/* Suppress procedure output */
ods exclude all;
/* Use PROC REG to obtain the parameter estimates and descriptive
statistics for a simple linear regression model */
ods graphics on;
proc reg data=sashelp.class;
model weight=height;
ods output fitplot=fitplotex1 fitstatistics=gofex1 parameterestimates=peex1 nobs=nex1 anova=aovex1;
quit;
/* Include subsequent procedure output */
ods select all;
/* Create macro variables for the statistics to add to the plot */
proc sql noprint;
select count(model) into :obs
from fitplotex1;
select count(model) into :parms
from peex1;
quit;
data _null_;
set aovex1;
where source='Error';
call symput('errdf',df);
call symput('mse',put(ms,comma7.2));
run;
data _null_;
set gofex1;
if label2='R-Square' then call symput('rsq',cvalue2);
if label2='Adj R-Sq' then call symput('adjrsq',cvalue2);
run;
data _null_;
set peex1 end=last;
retain intercept height;
if variable='Intercept' then Intercept=estimate;
if variable='Height' then Height=estimate;
if last then
call symput('eqn',"Weight="||Intercept||" + "||Height||"*Height");
run;
title 'PROC SGPLOT with Regression Equation and Descriptive Statistics';
proc sgplot data=sashelp.class;
reg y=weight x=height / clm cli;
inset ("Observations"="&obs"
"Parameters"= "&parms"
"Error DF"="&errdf"
"MSE"="&mse"
"R-Square"="&rsq"
"Adj R-Square"="&adjrsq")/ border position=bottomright;
inset "Regression Equation" "&eqn" / position=topleft;
run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> SGPLOT Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Statistical Graph Enhancements |
Date Modified: | 2019-12-12 08:55:00 |
Date Created: | 2019-12-05 10:27:23 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | Windows Vista | 9.2 TS1M0 | |
Windows Vista for x64 | 9.2 TS1M0 | |||
64-bit Enabled AIX | 9.2 TS1M0 | |||
64-bit Enabled HP-UX | 9.2 TS1M0 | |||
64-bit Enabled Solaris | 9.2 TS1M0 | |||
HP-UX IPF | 9.2 TS1M0 | |||
Linux | 9.2 TS1M0 | |||
Linux for x64 | 9.2 TS1M0 | |||
OpenVMS on HP Integrity | 9.2 TS1M0 | |||
Solaris for x64 | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |||
Microsoft Windows XP Professional | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |||
Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |||
Microsoft® Windows® for x64 | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |||
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |||
z/OS | 9.2 TS1M0 | |||
z/OS 64-bit | 9.2 TS1M0 |