turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Proc Reg versus Proc GLM using indicator variables

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

a week ago

Please assist with creating a proc reg and proc glm for the data below.

I have the proc reg statement; however I am unable to produce an output.

Can anyone explain what I am missing?

My goal is to:

1.Add a proc reg to your program to produce a regression with the two indicator variables.

2.Add a proc glm to your program that produces the ANOVA output using fertilizer as the class variable.

3. Compare both.

* create the dataset "herbs";

data herbs;

*input the variables, weight is the dry weight in grams, the fertilizer is A,B,or C;

input weight fertilizer$;

*use if then statements to create indicator variables;

if fertilizer='A' then A=1;else A=0;

if fertilizer='B' then B=1; else B=0;

*bring in the data through datalines;

datalines;

16.2 A

20.3 A

24.4 A

21.2 A

20.9 A

14.2 A

23.1 B

25.1 B

27.5 B

27.2 B

31.9 B

27.5 B

19.6 C

23.0 C

15.8 C

28.3 C

18.0 C

17.1 C

;

*print the dataset herbs to confirm that the varaibles were read in correctly;

proc print data=herbs;

run;

proc reg;

model weight=fertilizer$;

run;

Accepted Solutions

Solution

a week ago

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to SummerSol

a week ago

@SummerSol wrote:

proc reg data=herbs;

model weight = fertilizer;

run;produces this error:

104 model weight=fertilizer

ERROR: Variable fertilizer in list does not match type prescribed for this list.

Thanks and yes this is an assignment.

This type of error means fertilizer is a character and you need numeric variables to do regression in PROC REG. You did create the dummy variables (A, B) but didn't use them.

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to SummerSol

a week ago

proc reg; **<- no data statement - what is the data source here?**

model weight=fertilizer$; **<- why is there a dollar sign here? Use the name indicated in your data set, from the proc print or run a proc contents to see the name.**

run;

If something is not working, please include your log to show what errors you're getting. And if you're not sure how to use a PROC, see the examples and run the code to see how to set up your data and code.

@SummerSol wrote:

Please assist with creating a proc reg and proc glm for the data below.

I have the proc reg statement; however I am unable to produce an output.

Can anyone explain what I am missing?

My goal is to:

1.Add a proc reg to your program to produce a regression with the two indicator variables.

2.Add a proc glm to your program that produces the ANOVA output using fertilizer as the class variable.3. Compare both.

* create the dataset "herbs";

data herbs;

*input the variables, weight is the dry weight in grams, the fertilizer is A,B,or C;

input weight fertilizer$;

*use if then statements to create indicator variables;

if fertilizer='A' then A=1;else A=0;

if fertilizer='B' then B=1; else B=0;

*bring in the data through datalines;

datalines;

16.2 A

20.3 A

24.4 A

21.2 A

20.9 A

14.2 A

23.1 B

25.1 B

27.5 B

27.2 B

31.9 B

27.5 B

19.6 C

23.0 C

15.8 C

28.3 C

18.0 C

17.1 C

;

*print the dataset herbs to confirm that the varaibles were read in correctly;

proc print data=herbs;

run;proc reg;

model weight=fertilizer$;

run;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

a week ago

proc reg data=herbs;

model weight = fertilizer;

run;

produces this error:

104 model weight=fertilizer

ERROR: Variable fertilizer in list does not match type prescribed for this list.

Thanks and yes this is an assignment.

Solution

a week ago

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to SummerSol

a week ago

@SummerSol wrote:

proc reg data=herbs;

model weight = fertilizer;

run;produces this error:

104 model weight=fertilizer

ERROR: Variable fertilizer in list does not match type prescribed for this list.

Thanks and yes this is an assignment.

This type of error means fertilizer is a character and you need numeric variables to do regression in PROC REG. You did create the dummy variables (A, B) but didn't use them.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

a week ago

proc reg data=herbs;

model weight = A B;

run;

proc glm data=herbs;

class fertilizer;

model weight = fertilizer;

Thanks.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to SummerSol

a week ago

@SummerSol wrote:

proc reg data=herbs;

model weight = A B;

run;

proc glm data=herbs;

class fertilizer;

model weight = fertilizer;Thanks.

For A/B you wouldn't include both because it seems fertilizer has only 2 levels. This means you should have 1 dummy variable, not two. PROC GLM uses the over parameterized model though, so this would match that, but it's not good practice.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

a week ago

Thanks for the feedback. It was helpful

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to SummerSol

a week ago

@SummerSol wrote:

My goal is to:

1.Add a proc reg to your program to produce a regression with the two indicator variables.

2.Add a proc glm to your program that produces the ANOVA output using fertilizer as the class variable.3. Compare both.

Essentially, REG does not operate on categorical variables, they must be numeric. So, you could create columns of numeric 0s and 1s (dummy variables) to trick REG into doing the analysis.

By the way, you say "your goal is to:" even though this sounds very much like a homework assignment. If it is not a homework assignment, there's really no need for you to do both and compare them, the answer is well known.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PaigeMiller

a week ago

Thanks Paige. This is for a class assignment. I was just seeking help since this is my first class and I exhausted all my other resources.