proc glm data=ldl;
class trt;
model ldl3mo = ldlbase trt;
run;
proc sgplot data=ldl;
reg x=ldlbase y=ldl3mo / group = trt;
run;
Here is my code and my data set looks like as below. Ignore the first column; that's just the number of order.
I am trying to combine two plots: plain regression plot generated by proc reg and covariance plot generated by proc glm.
As you see plots below, scatter plots are identical. So I would like to know how to combine those regression lines on a single plot.
Thanks in advance
@monona wrote:
proc glm data=ldl; class trt; model ldl3mo = ldlbase trt; run; proc sgplot data=ldl; reg x=ldlbase y=ldl3mo / group = trt; run;
Here is my code and my data set looks like as below. Ignore the first column; that's just the number of order.
I am trying to combine two plots: plain regression plot generated by proc reg and covariance plot generated by proc glm.
As you see plots below, scatter plots are identical. So I would like to know how to combine those regression lines on a single plot.
Thanks in advance
You can capture the data used by the regression procedures by using ods output and the graph name found in the documentation.
For GLM the Analysis of Covariance plot is named Ancovaplot. so adding this statement to you GLM code:
ods output ancovaplot=work.ancovaplot;
Will create a data set named work.ancovaplot. Similarly you can create a data set from Proc Reg. You cleverly did not show your Proc Reg code so I can't guess which options or plots you requested and so won't guess which graphname you may want. The documentation for the procedure under details has a table of graphnames for each procedure and the options needed to create them.
You would need to combine the two data sets. Likely you would need to rename the predicted variable for one set.
Conceptually
data work.plot; set work.ancovaplot work.regplot (rename=(Predicted=RegPredicted)) ; run; Proc sgplot data=work.plot; scatter x=ldlbase y=ldl30/ group=trt; series x=ldlbase y=predicted/group=trt; series x=ldlbase y=regpredicted/ group=trt; run;
There may be details involved like variable labels for the predicted values and such.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.