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 |
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;
What is your question?
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 |
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.
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;
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 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.
Your textbook will give much better answers to these questions than I could, even if I had the time. Good luck with your studies.
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.