Quartz | Level 8

## Pleased help me solve for the regression analysis and interaction of two variables.

In a previous question, I requested some advise for obtaining the correct SAS codes for regression analysis and interaction, however it was not correct because the output did not include any parameter estimates.

To bring further clarity to the question above, How do I use  SAS to conduct the regression analysis for the following question: “Predict Energy Conservation Scores (ECS) using Consumer Attitude, Gender, and their interaction.

data PEC;

input energyconservationscale  studentattitudesscale gender;

datalines;

50  30 male

50  46 Female

30 45 male

38  36 Female

41  30 male

15  15 Female

20  38 male

15 50 Female

45 37 male

25  37 Female

45  47 male

50  29 Female

22  36 male

48  36 Female

40 37 male

30  14 Female

38  48 male

12  38 Female

12 18 male

15  25 Female

10  36 male

45  29 Female

24  26 male

34  27 Female

49  25 male

28 50 Female

25 26 male

10  38 Female

10 10 male

50 30 male

;

proc glm data=PEC;

class studentattitudescale gender;

model energyconservationscale studentattitudesscale gender;

output out=PECres residual=resid predicted=pred;

run;

proc univariate data=PECres normal;

var resid;

run;

17 REPLIES 17
Super User

## Re: Pleased help me solve for the regression analysis and interaction of two variables.

This is is what happens when you just run code without taking the time to understand what your doing.

https://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_glm_sect019...

MODEL Statement
MODEL dependent-variables = independent-effects </ options> ;

Look at the options in the documentation. One specifically states it will produce parameter estimates.

Give it a try. If you can't figure it out post what you've tried.

Ammonite | Level 13

## Re: Pleased help me solve for the regression analysis and interaction of two variables.

Try this.

proc glm data=PEC;

class gender;

model energyconservationscale = studentattitudesscale gender studentattitudesscale*gender;

output out=PECres residual=resid predicted=pred;

run;

Quartz | Level 8

## Re: Pleased help me solve for the regression analysis and interaction of two variables.

Hi Stat Sas,

I tried your code but it is still not happy.

Josie

Ammonite | Level 13

## Re: Pleased help me solve for the regression analysis and interaction of two variables.

Please expalin bit more. Not happy?

Quartz | Level 8

## Re: Pleased help me solve for the regression analysis and interaction of two variables.

The SAS codes did not work at all. Lots of errors in output.

Super User

## Re: Pleased help me solve for the regression analysis and interaction of two variables.

Any time you have a question about code producing errors, post the log with the code executed and the error messages. Just copy and paste into one a "run code" box provided with the Run icon in the message toolbar.

Ammonite | Level 13

Quartz | Level 8

## Re: Pleased help me solve for the regression analysis and interaction of two variables.

NOTE: Updated analytical products:

SAS/STAT 13.2
SAS/ETS 13.2
SAS/OR 13.2
SAS/IML 13.2
SAS/QC 13.2

X64_ES08R2 WIN 6.1.7601 Service Pack 1 Server

NOTE: SAS initialization used:
real time 16.21 seconds
cpu time 2.21 seconds

ERROR: Permanent copy of file SASUSER.PROFBAK.CATALOG was deleted.
1 data PEC;
2 input energyconservationscale studentattitudesscale gender;
3 datalines;

NOTE: Invalid data for gender in line 4 8-11.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+--
4 50 30 male
energyconservationscale=50 studentattitudesscale=30 gender=. _ERROR_=1 _N_=1
NOTE: Invalid data for gender in line 5 8-13.
5 50 46 Female
energyconservationscale=50 studentattitudesscale=46 gender=. _ERROR_=1 _N_=2
NOTE: Invalid data for gender in line 6 7-10.
6 30 45 male
energyconservationscale=30 studentattitudesscale=45 gender=. _ERROR_=1 _N_=3
NOTE: Invalid data for gender in line 7 8-13.
7 38 36 Female
energyconservationscale=38 studentattitudesscale=36 gender=. _ERROR_=1 _N_=4
NOTE: Invalid data for gender in line 8 8-11.
8 41 30 male
energyconservationscale=41 studentattitudesscale=30 gender=. _ERROR_=1 _N_=5
NOTE: Invalid data for gender in line 9 8-13.
9 15 15 Female
energyconservationscale=15 studentattitudesscale=15 gender=. _ERROR_=1 _N_=6
NOTE: Invalid data for gender in line 10 8-11.
10 20 38 male
energyconservationscale=20 studentattitudesscale=38 gender=. _ERROR_=1 _N_=7
NOTE: Invalid data for gender in line 11 7-12.
11 15 50 Female
energyconservationscale=15 studentattitudesscale=50 gender=. _ERROR_=1 _N_=8
NOTE: Invalid data for gender in line 12 7-10.
12 45 37 male
energyconservationscale=45 studentattitudesscale=37 gender=. _ERROR_=1 _N_=9
NOTE: Invalid data for gender in line 13 8-13.
13 25 37 Female
energyconservationscale=25 studentattitudesscale=37 gender=. _ERROR_=1 _N_=10
NOTE: Invalid data for gender in line 14 8-11.
14 45 47 male
energyconservationscale=45 studentattitudesscale=47 gender=. _ERROR_=1 _N_=11
NOTE: Invalid data for gender in line 15 8-13.
15 50 29 Female
energyconservationscale=50 studentattitudesscale=29 gender=. _ERROR_=1 _N_=12
NOTE: Invalid data for gender in line 16 8-11.
16 22 36 male
energyconservationscale=22 studentattitudesscale=36 gender=. _ERROR_=1 _N_=13
NOTE: Invalid data for gender in line 17 8-13.
17 48 36 Female
energyconservationscale=48 studentattitudesscale=36 gender=. _ERROR_=1 _N_=14
NOTE: Invalid data for gender in line 18 7-10.
18 40 37 male
energyconservationscale=40 studentattitudesscale=37 gender=. _ERROR_=1 _N_=15
NOTE: Invalid data for gender in line 19 8-13.
19 30 14 Female
energyconservationscale=30 studentattitudesscale=14 gender=. _ERROR_=1 _N_=16
NOTE: Invalid data for gender in line 20 8-11.
20 38 48 male
energyconservationscale=38 studentattitudesscale=48 gender=. _ERROR_=1 _N_=17
NOTE: Invalid data for gender in line 21 8-13.
21 12 38 Female
energyconservationscale=12 studentattitudesscale=38 gender=. _ERROR_=1 _N_=18
NOTE: Invalid data for gender in line 22 7-10.
22 12 18 male
energyconservationscale=12 studentattitudesscale=18 gender=. _ERROR_=1 _N_=19
NOTE: Invalid data for gender in line 23 8-13.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
23 15 25 Female
energyconservationscale=15 studentattitudesscale=25 gender=. _ERROR_=1 _N_=20
NOTE: The data set WORK.PEC has 30 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.04 seconds

34 ;
35
36 proc glm data=PEC;
37 class studentattitudescale gender;
NOTE: The previous statement has been deleted.
38 model energyconservationscale studentattitudesscale gender;
-
73
ERROR 73-322: Expecting an =.
39 output out=PECres residual=resid predicted=pred;
NOTE: The previous statement has been deleted.
40 run;

ERROR: A MODEL statement must be given.
41

NOTE: The data set WORK.PECRES has 0 observations and 0 variables.
NOTE: PROCEDURE GLM used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds

42 proc univariate data=PECres normal;
NOTE: Writing HTML Body file: sashtml.htm
43 var resid;
44 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE UNIVARIATE used (Total process time):
real time 0.77 seconds
cpu time 0.45 seconds

45 data PEC;
46 input energyconservationscale studentattitudesscale gender;
47 datalines;

NOTE: Invalid data for gender in line 48 8-11.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+--
48 50 30 male
energyconservationscale=50 studentattitudesscale=30 gender=. _ERROR_=1 _N_=1
NOTE: Invalid data for gender in line 49 8-13.
49 50 46 Female
energyconservationscale=50 studentattitudesscale=46 gender=. _ERROR_=1 _N_=2
NOTE: Invalid data for gender in line 50 7-10.
50 30 45 male
energyconservationscale=30 studentattitudesscale=45 gender=. _ERROR_=1 _N_=3
NOTE: Invalid data for gender in line 51 8-13.
51 38 36 Female
energyconservationscale=38 studentattitudesscale=36 gender=. _ERROR_=1 _N_=4
NOTE: Invalid data for gender in line 52 8-11.
52 41 30 male
energyconservationscale=41 studentattitudesscale=30 gender=. _ERROR_=1 _N_=5
NOTE: Invalid data for gender in line 53 8-13.
53 15 15 Female
energyconservationscale=15 studentattitudesscale=15 gender=. _ERROR_=1 _N_=6
NOTE: Invalid data for gender in line 54 8-11.
54 20 38 male
energyconservationscale=20 studentattitudesscale=38 gender=. _ERROR_=1 _N_=7
NOTE: Invalid data for gender in line 55 7-12.
55 15 50 Female
energyconservationscale=15 studentattitudesscale=50 gender=. _ERROR_=1 _N_=8
NOTE: Invalid data for gender in line 56 7-10.
56 45 37 male
energyconservationscale=45 studentattitudesscale=37 gender=. _ERROR_=1 _N_=9
NOTE: Invalid data for gender in line 57 8-13.
57 25 37 Female
energyconservationscale=25 studentattitudesscale=37 gender=. _ERROR_=1 _N_=10
NOTE: Invalid data for gender in line 58 8-11.
58 45 47 male
energyconservationscale=45 studentattitudesscale=47 gender=. _ERROR_=1 _N_=11
NOTE: Invalid data for gender in line 59 8-13.
59 50 29 Female
energyconservationscale=50 studentattitudesscale=29 gender=. _ERROR_=1 _N_=12
NOTE: Invalid data for gender in line 60 8-11.
60 22 36 male
energyconservationscale=22 studentattitudesscale=36 gender=. _ERROR_=1 _N_=13
NOTE: Invalid data for gender in line 61 8-13.
61 48 36 Female
energyconservationscale=48 studentattitudesscale=36 gender=. _ERROR_=1 _N_=14
NOTE: Invalid data for gender in line 62 7-10.
62 40 37 male
energyconservationscale=40 studentattitudesscale=37 gender=. _ERROR_=1 _N_=15
NOTE: Invalid data for gender in line 63 8-13.
63 30 14 Female
energyconservationscale=30 studentattitudesscale=14 gender=. _ERROR_=1 _N_=16
NOTE: Invalid data for gender in line 64 8-11.
64 38 48 male
energyconservationscale=38 studentattitudesscale=48 gender=. _ERROR_=1 _N_=17
NOTE: Invalid data for gender in line 65 8-13.
65 12 38 Female
energyconservationscale=12 studentattitudesscale=38 gender=. _ERROR_=1 _N_=18
NOTE: Invalid data for gender in line 66 7-10.
66 12 18 male
energyconservationscale=12 studentattitudesscale=18 gender=. _ERROR_=1 _N_=19
NOTE: Invalid data for gender in line 67 8-13.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
67 15 25 Female
energyconservationscale=15 studentattitudesscale=25 gender=. _ERROR_=1 _N_=20
NOTE: The data set WORK.PEC has 30 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.06 seconds

78 ;
79
80 proc glm data=PEC;
81 class studentattitudescale gender;
NOTE: The previous statement has been deleted.
82 model energyconservationscale studentattitudesscale gender;
-
73
ERROR 73-322: Expecting an =.
83 output out=PECres residual=resid predicted=pred;
NOTE: The previous statement has been deleted.
84 run;

ERROR: A MODEL statement must be given.
85

NOTE: The data set WORK.PECRES has 0 observations and 0 variables.
WARNING: Data set WORK.PECRES was not replaced because new file is incomplete.
NOTE: PROCEDURE GLM used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

86 proc univariate data=PECres normal;
87 var resid;
88 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE UNIVARIATE used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

89 data PEC;
90 input energyconservationscale studentattitudesscale gender;
91 datalines;

NOTE: Invalid data for gender in line 92 8-11.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+--
92 50 30 male
energyconservationscale=50 studentattitudesscale=30 gender=. _ERROR_=1 _N_=1
NOTE: Invalid data for gender in line 93 8-13.
93 50 46 Female
energyconservationscale=50 studentattitudesscale=46 gender=. _ERROR_=1 _N_=2
NOTE: Invalid data for gender in line 94 7-10.
94 30 45 male
energyconservationscale=30 studentattitudesscale=45 gender=. _ERROR_=1 _N_=3
NOTE: Invalid data for gender in line 95 8-13.
95 38 36 Female
energyconservationscale=38 studentattitudesscale=36 gender=. _ERROR_=1 _N_=4
NOTE: Invalid data for gender in line 96 8-11.
96 41 30 male
energyconservationscale=41 studentattitudesscale=30 gender=. _ERROR_=1 _N_=5
NOTE: Invalid data for gender in line 97 8-13.
97 15 15 Female
energyconservationscale=15 studentattitudesscale=15 gender=. _ERROR_=1 _N_=6
NOTE: Invalid data for gender in line 98 8-11.
98 20 38 male
energyconservationscale=20 studentattitudesscale=38 gender=. _ERROR_=1 _N_=7
NOTE: Invalid data for gender in line 99 7-12.
99 15 50 Female
energyconservationscale=15 studentattitudesscale=50 gender=. _ERROR_=1 _N_=8
NOTE: Invalid data for gender in line 100 7-10.
100 45 37 male
energyconservationscale=45 studentattitudesscale=37 gender=. _ERROR_=1 _N_=9
NOTE: Invalid data for gender in line 101 8-13.
101 25 37 Female
energyconservationscale=25 studentattitudesscale=37 gender=. _ERROR_=1 _N_=10
NOTE: Invalid data for gender in line 102 8-11.
102 45 47 male
energyconservationscale=45 studentattitudesscale=47 gender=. _ERROR_=1 _N_=11
NOTE: Invalid data for gender in line 103 8-13.
103 50 29 Female
energyconservationscale=50 studentattitudesscale=29 gender=. _ERROR_=1 _N_=12
NOTE: Invalid data for gender in line 104 8-11.
104 22 36 male
energyconservationscale=22 studentattitudesscale=36 gender=. _ERROR_=1 _N_=13
NOTE: Invalid data for gender in line 105 8-13.
105 48 36 Female
energyconservationscale=48 studentattitudesscale=36 gender=. _ERROR_=1 _N_=14
NOTE: Invalid data for gender in line 106 7-10.
106 40 37 male
energyconservationscale=40 studentattitudesscale=37 gender=. _ERROR_=1 _N_=15
NOTE: Invalid data for gender in line 107 8-13.
107 30 14 Female
energyconservationscale=30 studentattitudesscale=14 gender=. _ERROR_=1 _N_=16
NOTE: Invalid data for gender in line 108 8-11.
108 38 48 male
energyconservationscale=38 studentattitudesscale=48 gender=. _ERROR_=1 _N_=17
NOTE: Invalid data for gender in line 109 8-13.
109 12 38 Female
energyconservationscale=12 studentattitudesscale=38 gender=. _ERROR_=1 _N_=18
NOTE: Invalid data for gender in line 110 7-10.
110 12 18 male
energyconservationscale=12 studentattitudesscale=18 gender=. _ERROR_=1 _N_=19
NOTE: Invalid data for gender in line 111 8-13.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
111 15 25 Female
energyconservationscale=15 studentattitudesscale=25 gender=. _ERROR_=1 _N_=20
NOTE: The data set WORK.PEC has 30 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.04 seconds

122 ;
123
124 proc glm data=PEC;
125 class gender;
126 model energyconservationscale = studentattitudesscale gender studentattitudesscale*gender;
127 output out=PECres residual=resid predicted=pred;
128 run;

ERROR: One or more variables are missing or freq or weight is zero on every observation.

Ammonite | Level 13

## Re: Pleased help me solve for the regression analysis and interaction of two variables.

Problem is with data creation. As gender is a character variable, just put \$ sign with gender in you input statement.

data PEC;

input energyconservationscale  studentattitudesscale gender \$;

datalines;

50  30 male

50  46 Female

30 45 male

38  36 Female

41  30 male

15  15 Female

20  38 male

15 50 Female

45 37 male

25  37 Female

45  47 male

50  29 Female

22  36 male

48  36 Female

40 37 male

30  14 Female

38  48 male

12  38 Female

12 18 male

15  25 Female

10  36 male

45  29 Female

24  26 male

34  27 Female

49  25 male

28 50 Female

25 26 male

10  38 Female

10 10 male

50 30 male

;

Quartz | Level 8

## Re: Pleased help me solve for the regression analysis and interaction of two variables.

Thank you for the \$ gender reminder. Silly me . The output looks good however, it still does not contain the.parameter estimates

which I really need.

Josie

Ammonite | Level 13

## Re: Pleased help me solve for the regression analysis and interaction of two variables.

which parameter estimates are you looking for?

Super User

RTM

## Re: Pleased help me solve for the regression analysis and interaction of two variables.

I will wager 1 quadrillion Zimbabwean dollars that the parameter estimates obtained are "confusing", as the factors in the model are both in the CLASS statement, and hence really aren't regression parameters.  They are "incremental changes" with level changes in the class variables.

Steve Denham

Super User

## Re: Pleased help me solve for the regression analysis and interaction of two variables.

@SteveDenham I wouldn't take that bet...

Discussion stats
• 17 replies
• 3218 views
• 5 likes
• 5 in conversation