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;
@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.
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;
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.
@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.
proc reg data=herbs;
model weight = A B;
run;
proc glm data=herbs;
class fertilizer;
model weight = fertilizer;
Thanks.
@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.
Thanks for the feedback. It was helpful
@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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.