SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
gkmzinsou
Calcite | Level 5

Hi,

I am having a hard time understanding the ANCOVA model and how to implement it in SAS.

 

I am supposed to do an ANCOVA to obtain adjusted means and adjusted means differences for Y = change from baseline using treatment as a factor variable (3 categories), country as a categorical covariate (5 categories) and baseline as a continuous variable (hence the need for ANCOVA), the last two being adjustment variables. 

 

I have to use proc mixed and not proc glm or proc reg (Although I would love to know how it's done using these models as well).

 

My SAS code looks something like:

proc mixed data = mydata;

ods output lsmeans = ls_means;

class trt country;

model change = trt country baseline;

lsmeans trt / pdiff cov ;

run;

 

Is this correct? I also learned that an ANCOVA model requires the centering of the continuous variable. Is this something that has to be done manually or is it automatically done through SAS? I read somewhere that SPSS and R do it automatically. I know that the ANCOVA model looks something like this:

gkmzinsou_0-1618869759218.png

 

gkmzinsou_1-1618869772032.png

 

How do I write my model in this form(knowing that I have an extra categorical adjustment variable)? Or can I just write it as a regression model:

Change = Bo + B1 treat1 + B2 treat2 + B3 country1 + B4 country2 + B5 country3 + B6 country4 + B7 baseline + error (treat 3 = ref and country5 = ref)?

 

One last thing : I am supposed to do a sequential comparison. 

Treat 1 vs Treat 3

Treat 2 vs Treat 3

Treat 1 vs Treat 2

How do I do that in SAS? Do I use the estimate options? I'm not too sure how that works either. 

 

Any and all help would be appreciated!

 

1 REPLY 1
PaigeMiller
Diamond | Level 26

I think the code you provided works for ANCOVA.

 

I don't think centering of the continuous variable is required; SAS does not do this automatically.

 

The PDIFF option of LSMEANS gets you the comparisons of the levels of TRT; there's no need to use LSMESTIMATE for comparing one level to another.

--
Paige Miller

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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