Using SAS 9.4
Is there a way to take the r-squared from
proc reg data= pt.eligible;
model impingment_point = ptp_translation /selection=rsquare;
run;
and add it to the graph I have using proc sgplot?
proc sgplot data = pt.eligible;
scatter x=ptp_translation y=impingment_point;
yaxis min=0 max=140 label = 'Distance to Impingement of 12 mm Stem Against Endosteal Surface';
xaxis min=0 max=40 label = 'Percentage Translation Between Sagittal Anatomic Axis and Joint Line Center';
title 'Proximal Tibial Translation and Distance to Impingement of a 12 mm Tibial Stem';
run;
Here is an example using proc reg:
proc reg data=sashelp.cars plots=none;
where cylinders=4;
model horsepower = engineSize / rsquare;
output out=preds predicted=p_horsePower;
/* Use ods to output the r-square value into a dataset */
ods output fitStatistics=fs;
run;
quit;
/* Transfer the r-square value to a macro variable named RSQ */
data _null_;
set fs;
where label2="Adj R-Sq";
call symputx("RSQ", put(nvalue2, percentn7.1));
run;
proc sort data=preds; by engineSize; run;
proc sgplot data=preds noautolegend;
title "Horse Power for 4-cylinder engines";
scatter y=horsePower x=engineSize;
series y=p_horsePower x=engineSize;
inset ("Adj. R-Square:" = "&RSQ") / position=bottomright;
run;
How do you want it to appear?
Since you are not using an output dataset from Proc Reg you might try adding a footnote or title with the text and value.
Or create an annotate data set with the value and appearance options you want.
Here is an example using proc reg:
proc reg data=sashelp.cars plots=none;
where cylinders=4;
model horsepower = engineSize / rsquare;
output out=preds predicted=p_horsePower;
/* Use ods to output the r-square value into a dataset */
ods output fitStatistics=fs;
run;
quit;
/* Transfer the r-square value to a macro variable named RSQ */
data _null_;
set fs;
where label2="Adj R-Sq";
call symputx("RSQ", put(nvalue2, percentn7.1));
run;
proc sort data=preds; by engineSize; run;
proc sgplot data=preds noautolegend;
title "Horse Power for 4-cylinder engines";
scatter y=horsePower x=engineSize;
series y=p_horsePower x=engineSize;
inset ("Adj. R-Square:" = "&RSQ") / position=bottomright;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.