Learner
Posts: 1

# Using Proc GLM with Categorical Variables/How to get Post Hoc results

Hi everyone. I am new-ish to using SAS and am hoping for some help on if my code is correct for what I am after. I have the following variables:

Medications: the total number of medications taken per person

Sex
1=male

2=female

AgeGroups

1=20-25

2=26-29

3=30-34

Interaction between Sex and AgeGroups:

AgeGroups*Sex

Income

1=Less than 20k

2=20,000 – 49,999

3=50,000 – 79,999

4=80,000 – 99,999

5=100,000 or more

I want to find out if any of the categorical demographic variables have a significant effect on the number of medications. Then I want to find out where the significant differences are between groups. I am using linear regression. After some Google searching, I have come up with the following code. Is it correct to get what I am looking for? Thanks.

proc glm data=mydata;
class Sex AgeGroups Income;
model Medications=Sex AgeGroups Income AgeGroups*Sex /solution;
lsmeans Sex AgeGroups Income AgeGroups*Sex /adjust=scheffe;
run; quit;

Posts: 5,529

## Re: Using Proc GLM with Categorical Variables/How to get Post Hoc results

model Medications=Sex|AgeGroups|Income;

PG
Posts: 3,019

## Re: Using Proc GLM with Categorical Variables/How to get Post Hoc results

@someone456 wrote:

Hi everyone. I am new-ish to using SAS and am hoping for some help on if my code is correct for what I am after. I have the following variables:

Medications: the total number of medications taken per person

Sex
1=male

2=female

AgeGroups

1=20-25

2=26-29

3=30-34

Interaction between Sex and AgeGroups:

AgeGroups*Sex

Income

1=Less than 20k

2=20,000 – 49,999

3=50,000 – 79,999

4=80,000 – 99,999

5=100,000 or more

I want to find out if any of the categorical demographic variables have a significant effect on the number of medications. Then I want to find out where the significant differences are between groups. I am using linear regression. After some Google searching, I have come up with the following code. Is it correct to get what I am looking for? Thanks.

proc glm data=mydata;
class Sex AgeGroups Income;
model Medications=Sex AgeGroups Income AgeGroups*Sex /solution;
lsmeans Sex AgeGroups Income AgeGroups*Sex /adjust=scheffe;
run; quit;

Your question about differences between groups is answered by the LSMEANS statement. So I think this is the correct code.

--
Paige Miller
PROC Star
Posts: 404

## Re: Using Proc GLM with Categorical Variables/How to get Post Hoc results

I agree with @PaigeMiller that you are on the right track.

I agree with @PGStats that you need to consider whether to exclude other potential interactions among the fixed effects (and be able to justify their exclusion).

In addition, I would think of this as an ANOVA rather than a regression. Of course ANOVA is really just a special case of regression, but there are things we can apply in ANOVA models that we don't apply in regression (like LSMEANS as @PaigeMiller suggested). ANOVA models have assumptions (notably, normality and homogeneity of variance and independence) that you would need to assess for your analysis. SAS® for Linear Models, Fourth Edition is an excellent resource; these are topics that are also covered extensively in courses, and so there are resources available on the internet, in books, etc.

I hope this helps.

Discussion stats
• 3 replies
• 227 views
• 2 likes
• 4 in conversation