Help using Base SAS procedures

SAS code for simple linear regression not correct please help.

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

SAS code for simple linear regression not correct please help.

data case2;
input sleeptime $ lifesatisfaction;
datalines
st 7.5
st 8.3
st 9.5
st 8.5
st 6.0
st 8.0
st 7.3
st 7.0
st 8.0
st 6.5
ls 23
ls 19
ls 16
ls 20
ls 40
ls 22
ls 30
ls 25
ls 30
ls 36
;
proc reg data case2;
model lifesatisfaction = sleeptime;
run;
quit;

 

 

A researcher hypothesizes that undergraduate students who are satisfied with their lives will sleep less than those who are not satisfied. To test this hypothesis, she selects a sample of undergraduate students and asks them to maintain a “sleep log” (Drowsy, 1977), keeping track of the number of hours they sleep during each 24-hour period. These logs are maintained for two weeks. At the end of the two-week period, each participant completes the Satisfaction with Life Scale (Giggle & Smirk, 1969), a reliable, validated measure of general satisfaction with life.

 

These are the data the researcher obtained:

 

Participant

Mean Hours of Sleep

SWL Score

01

7.5

23

02

8.3

19

03

9.5

16

04

8.5

20

05

6.0

40

06

8.0

22

07

7.3

30

08

7.0

25

09

8.0

30

10

6.5

36


Accepted Solutions
Solution
‎03-20-2016 10:36 PM
Respected Advisor
Posts: 4,655

Re: SAS code for simple linear regression not correct please help.

Just a few syntax fixes:

 

data case2;
input sleeptime lifesatisfaction;
datalines;
7.5 23
8.3 19
9.5 16
8.5 20
6.0 40
8.0 22
7.3 30
7.0 25
8.0 30
6.5 36
7.5 23
8.3 19
9.5 16
8.5 20
6.0 40
8.0 22
7.3 30
7.0 25
8.0 30
6.5 36
7.5 23
8.3 19
9.5 16
8.5 20
6.0 40
8.0 22
7.3 30
7.0 25
8.0 30
6.5 36
;

proc reg data=case2;
model lifesatisfaction = sleeptime / p r;
output out=case2Out residual=resid1;
run;
quit;

proc univariate plot data=case2Out normal;
var resid1;
run;
PG

View solution in original post


All Replies
Super User
Posts: 17,907

Re: SAS code for simple linear regression not correct please help.

What is your question?

Contributor
Posts: 46

Re: SAS code for simple linear regression not correct please help.

Reeza, thank you for your previous info you provided with regard to SAS linear regression code. I attempted it but was unsuccessful. Error messages occurred.

Here are my SAS codes.

 

data case2;
input sleeptime $ lifesatisfaction;
datalines;
7.5 23
8.3 19
9.5 16
8.5 20
6.0 40
8.0 22
7.3 30
7.0 25
8.0 30
6.5 36
7.5 23
8.3 19
9.5 16
8.5 20
6.0 40
8.0 22
7.3 30
7.0 25
8.0 30
6.5 36
7.5 23
8.3 19
9.5 16
8.5 20
6.0 40
8.0 22
7.3 30
7.0 25
8.0 30
6.5 36
;
proc reg data case2;
model lifesatisfaction = sleeptime / p r;
plot predicted * sleeptime = 'p' lifesatisfaction * sleeptime = '*'/ overlay;
plot residual.* predicted.;
output sleeptime $ lifesatisfaction residual=resid1;
proc univariate plot data=case2;
var resid1;
run;

A researcher hypothesizes that undergraduate students who are satisfied with their lives will sleep less than those who are not satisfied. To test this hypothesis, she selects a sample of undergraduate students and asks them to maintain a “sleep log” (Drowsy, 1977), keeping track of the number of hours they sleep during each 24-hour period. These logs are maintained for two weeks. At the end of the two-week period, each participant completes the Satisfaction with Life Scale (Giggle & Smirk, 1969), a reliable, validated measure of general satisfaction with life.

 

These are the data the researcher obtained:

 

Participant

Mean Hours of Sleep

SWL Score

01

7.5

23

02

8.3

19

03

9.5

16

04

8.5

20

05

6.0

40

06

8.0

22

07

7.3

30

08

7.0

25

09

8.0

30

10

6.5

36

 

Respected Advisor
Posts: 4,655

Re: SAS code for simple linear regression not correct please help.

If you enter the data the researcher obtained, in the format the researcher provided, i.e. one observation per subject, you will be able to perform your homework regression. 

PG
Contributor
Posts: 46

Re: SAS code for simple linear regression not correct please help.

I tried that but I am still getting many errors.

data case2;
input sleeptime $ lifesatisfaction;
datalines;
7.5 23
8.3 19
9.5 16
8.5 20
6.0 40
8.0 22
7.3 30
7.0 25
8.0 30
6.5 36
7.5 23
8.3 19
9.5 16
8.5 20
6.0 40
8.0 22
7.3 30
7.0 25
8.0 30
6.5 36
7.5 23
8.3 19
9.5 16
8.5 20
6.0 40
8.0 22
7.3 30
7.0 25
8.0 30
6.5 36
;
proc reg data case2;
model lifesatisfaction = sleeptime / p r;
plot predicted * sleeptime = 'p' lifesatisfaction * sleeptime = '*'/ overlay;
plot residual.* predicted.;
output sleeptime $ lifesatisfaction residual=resid1;
proc univariate plot data=case2;
var resid1;
run;
quit;

Solution
‎03-20-2016 10:36 PM
Respected Advisor
Posts: 4,655

Re: SAS code for simple linear regression not correct please help.

Just a few syntax fixes:

 

data case2;
input sleeptime lifesatisfaction;
datalines;
7.5 23
8.3 19
9.5 16
8.5 20
6.0 40
8.0 22
7.3 30
7.0 25
8.0 30
6.5 36
7.5 23
8.3 19
9.5 16
8.5 20
6.0 40
8.0 22
7.3 30
7.0 25
8.0 30
6.5 36
7.5 23
8.3 19
9.5 16
8.5 20
6.0 40
8.0 22
7.3 30
7.0 25
8.0 30
6.5 36
;

proc reg data=case2;
model lifesatisfaction = sleeptime / p r;
output out=case2Out residual=resid1;
run;
quit;

proc univariate plot data=case2Out normal;
var resid1;
run;
PG
Contributor
Posts: 46

Re: SAS code for simple linear regression not correct please help.

Thank you so very much PG stats. I see now where I made syntax errors. I do appreciate you help very much. Josie
Contributor
Posts: 46

Re: SAS code for simple linear regression not correct please help.

PG STATS,

 

Thank you very much for your assistance with the SAS syntax of the Satisfaction with life problem.

 Could you tell me where I can get any information on analyzing the output of the SAS  problem you assisted me with.

 

I realise that in order to know how to do the problems and to prepare for my final exams, I will need to know how to  answer the specific answers. I have been able to answer quite a few questions regarding the null hypothesis, regression equation etc,. Some questions I am struggling to answer are:

1. 

  1. What is “the predicted mean hours of sleep” for someone with an SWL score of 32? 
  2. What are “the predicted mean hours of sleep” and “the residual” for research participant #7? 
  3. What is the value for regression of sums-of-squares (SSreg)?
  4. What is the value for the standard error of estimate? 
  5. What are the values for coefficients of determination and alienation? 
  6. We would like to test if the proportion of the variance is significantly accounted for by the predictor. What is the null hypothesis? What is the statistic we use to test this hypothesis? What is your decision (reject or fail to reject)
  7. We would also like to test if the slope differs significant from 0. What is the null hypothesis? What is the statistic we use to test this hypothesis? 
  8. Regarding outlier diagnosis, which participants are more likely potential outliers?
Respected Advisor
Posts: 4,655

Re: SAS code for simple linear regression not correct please help.

Your textbook will give much better answers to these questions than I could, even if I had the time. Good luck with your studies.

PG
Super User
Posts: 17,907

Re: SAS code for simple linear regression not correct please help.

Post your log. What errors are you receiving? Your 'question' looks strongly like homework or training so I don't like to answer those questions unless they are very specific. This is my opinion and guidelines only, not the community.
Contributor
Posts: 46

Re: SAS code for simple linear regression not correct please help.

This is the message in the log after I posted my SAS code.

 

 

data case2;
2 input sleeptime $ lifesatisfaction;
3 datalines;

NOTE: The data set WORK.CASE2 has 30 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.14 seconds
cpu time 0.01 seconds


34 ;
35 proc reg data case2;
-----
73
NOTE: Writing HTML Body file: sashtml.htm
ERROR 73-322: Expecting an =.
36 model lifestatisfaction = sleeptime;
ERROR: Variable LIFESTATISFACTION not found.
ERROR: Variable sleeptime in list does not match type prescribed for this list.
NOTE: The previous statement has been deleted.
37 run;

WARNING: No variables specified for an SSCP matrix. Execution terminating.
NOTE: PROCEDURE REG used (Total process time):
real time 2.09 seconds
cpu time 0.28 seconds


38 quit;

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 460 views
  • 3 likes
  • 3 in conversation