BookmarkSubscribeRSS Feed
monona
Obsidian | Level 7

 

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.

 

 Untitled.png

 

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. 

Untitled.png

 

Thanks in advance

1 REPLY 1
ballardw
Super User

@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.

 

 Untitled.png

 

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1050 views
  • 0 likes
  • 2 in conversation