BookmarkSubscribeRSS Feed
cjacks21
Calcite | Level 5

Hello I a new to SAS. I am creating a model that looks at the mean HIV viral load over time by gender, race/ethnicity, age group, residency, HIV risk exposure, and first (baseline) cd4 count. I know how the use the  CLASS variable and ( "REF= option") to look at the difference in viral load by variable with only 2 levels. I want to compare results with a variable with more than 2 levels. For example race/ethnicity has 3 levels: Black, White, and Other. So I want to compare Black to White, Black to Other, and  White to Other and for risk exposure the same thing compare: Injecting Drug Use, MSM, MSM/Injecting Drug Use, and Other. Compare every risk exposure to each other. My proc mixed SAS code is below:

 

*sort data set with average viral load;
proc sort data = avgvlqrt out= avgvlqrt_sorted nodupkey;
by rfa_id time avgvl;
run;

 

*Proc mix to look at youth mean viral load by residence, cd4, sex, race, and gender ;
PROC MIXED data= avgvlqrt_sorted covtest noclprint noitprint method=reml PLOTS(MAXPOINTS=NONE);
class sex_hars (ref="F") res_at_hiv_dx (ref="Urban") race_combined (ref="White") agegroupdx (ref="Adolesce") risk_hars_n (ref="Heterosexual") cd4base_dx (ref="< 200");
model avgvl= time sex_hars res_at_hiv_dx race_combined risk_hars_n agegroupdx cd4base_dx / solution;
random time / subject=rfa_id Type= un vcorr;
RUN;

 

11 REPLIES 11
PaigeMiller
Diamond | Level 26

The LSMEANS statement (with options such as DIFF and possibly others) allows you to compare the means of the different levels of class variables.

--
Paige Miller
cjacks21
Calcite | Level 5

Thank you for replying.  What if I want to compare the different levels with just one class variable?

cjacks21
Calcite | Level 5

Okay. Great. So I can add the LSMEAN statement into the proc mixed code like the following below. I put the LSMEAN line in bold. Would this be correct?

 

*sort data set with average viral load;
proc sort data = avgvlqrt out= avgvlqrt_sorted nodupkey;
by rfa_id time avgvl;
run;

 

*Proc mix to look at youth mean viral load by residence, cd4, sex, race, and gender ;
PROC MIXED data= avgvlqrt_sorted covtest noclprint noitprint method=reml PLOTS(MAXPOINTS=NONE);
class sex_hars (ref="F") res_at_hiv_dx (ref="Urban") race_combined (ref="White") agegroupdx (ref="Adolesce") risk_hars_n (ref="Heterosexual") cd4base_dx (ref="< 200");
model avgvl= time sex_hars res_at_hiv_dx race_combined risk_hars_n agegroupdx cd4base_dx / solution;

lsmeans race_combined  risk_hars_n race_combined *risk_hars_n;

random time / subject=rfa_id Type= un vcorr;
RUN;

PaigeMiller
Diamond | Level 26

Looks good to me. Does the output make sense?

--
Paige Miller
cjacks21
Calcite | Level 5

I am getting an error so I do not have the result yet. ERROR: Effects used in the LSMEANS statement must have appeared previously in the MODEL statement. I also attached a screenshot.

 

 

PaigeMiller
Diamond | Level 26

Your LSMEANS statement has an interaction, but there is no interaction in the MODEL statement.

--
Paige Miller
cjacks21
Calcite | Level 5

Okay. I see. Thank you. I added the iteration to the model and got a result.  SAS Code below and the results are attached. One last question. Need help interpreting the results. I want to know if there is a difference in viral load over time with White to Black, Black to Other, and White to Other. Where can I locate this in the results? I am using the book SAS for Mixed Models Introduction and Basic Applications to help me learn about mixed models.

 

*sort data set with average viral load by rfa_id time and average viral load;


proc sort data = avgvlqrt out= avgvlqrt_sorted nodupkey; *remove duplicates;
by rfa_id time avgvl;
run;

 

*Proc mix to look at youth mean viral load by residence, cd4, sex, race, and gender ;


PROC MIXED data= avgvlqrt_sorted covtest noclprint noitprint method=reml PLOTS(MAXPOINTS=NONE);
class sex_hars (ref="F") res_at_hiv_dx (ref="Urban") race_combined (ref="White") agegroupdx (ref="Adolesce") risk_hars_n (ref="Heterosexual") cd4base_dx (ref="< 200");
model avgvl= time sex_hars res_at_hiv_dx race_combined risk_hars_n agegroupdx cd4base_dx race_combined*risk_hars_n/ solution;
lsmeans race_combined risk_hars_n race_combined*risk_hars_n;
random time / subject=rfa_id Type= un vcorr;
RUN;

PaigeMiller
Diamond | Level 26

If you scroll down to where it says "Least Squares Means", you can see that the mean of Blacks is 3.0401, and so on. Is this statistically different from the mean of the other levels? You need to add the /DIFF option (and possibly other options as desired) into the LSMEANS statement. 

--
Paige Miller
cjacks21
Calcite | Level 5

Okay. I believe I have something. I added the \Diff statement in the LSMEANS line and I think I can see that the class variable race_combined and risk exposure are compared between the each other and the different levels between each. Is this correct?

PaigeMiller
Diamond | Level 26

@cjacks21 wrote:

Okay. I believe I have something. I added the \Diff statement in the LSMEANS line and I think I can see that the class variable race_combined and risk exposure are compared between the each other and the different levels between each. Is this correct?


Not sure what you are looking at, so I can't say if you are correct or not. In the future, please show the portion of the results you are looking at as a screen capture here in your message. Most people, including me, do not download attachments.

--
Paige Miller

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 11 replies
  • 2647 views
  • 1 like
  • 2 in conversation