0% found this document useful (0 votes)
10 views3 pages

Code - Homework 29.sas

The document contains SAS code for a homework assignment involving three statistical analyses: an ANOVA for cholesterol treatment effects, a GLM for depression scores with interaction plots, and a correlation and t-test analysis for IQ and score data across two groups. Each section includes data preparation, statistical modeling, and visualization steps. The code demonstrates the use of arrays, loops, and various SAS procedures to analyze and interpret the data.

Uploaded by

jongmyeong WEE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Code - Homework 29.sas

The document contains SAS code for a homework assignment involving three statistical analyses: an ANOVA for cholesterol treatment effects, a GLM for depression scores with interaction plots, and a correlation and t-test analysis for IQ and score data across two groups. Each section includes data preparation, statistical modeling, and visualization steps. The code demonstrates the use of arrays, loops, and various SAS procedures to analyze and interpret the data.

Uploaded by

jongmyeong WEE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

4/11/25, 10:04 AM Code: Homework 29.

sas

/* Question 1 */
data cholesterol;
infile '/home/u64124859/cody_chap07_num02-1.dat';
input value1-value10;
array values{10} value1-value10;

do i = 1 to 10;
value = values{i};
if i <= 10 then treatment = 'Statin1';
else if i <= 20 then treatment = 'Statin2';
else treatment = 'Placebo';
output;
end;

drop value1-value10 i;
run;

proc anova data=cholesterol;


class treatment;
model value = treatment;
means treatment / snk;
run;

/* Question 2 */
data depression;
array scores[2,2,4] _temporary_ (
9 11 10 10, 9 6 6 7,
5 4 7 7, 12 11 10 11
);

do group = 1 to 2;
do trt = 1 to 2;
do rep = 1 to 4;
score = scores[group, trt, rep];
if group = 1 then group_label = 'Deficiency';
else if group = 2 then group_label = 'Normal';

if trt = 1 then trt_label = 'Drug';


else if trt = 2 then trt_label = 'Placebo';

output;
end;
end;
end;
run;

proc glm data=depression;


class group_label trt_label;
about:blank 1/3
4/11/25, 10:04 AM Code: Homework 29.sas
model score = group_label trt_label group_label*trt_label;
run;

proc means data=depression noprint;


class group_label trt_label;
var score;
output out=means_avg mean=mean_score;
run;

symbol1 v=dot i=join c=blue;


symbol2 v=dot i=join c=red;

proc gplot data=means_avg;


where _TYPE_ = 3;
plot mean_score * trt_label = group_label;
title 'Interaction Plot: Group × Treatment';
run;
quit;

/* Question 3 */
DATA co_vary;
DO I = 1 TO 20;
DO GROUP = 'A','B';
SUBJ + 1;
IQ = INT(RANNOR(124)*10 + 120 + 15*(GROUP EQ 'A'));
SCORE = INT(.7*IQ + RANNOR(0)*10 + 100 + 10*(GROUP EQ 'B'));
OUTPUT;
END;
END;
DROP I;
RUN;

PROC PRINT data = co_vary NOOBS;


title 'The co_vary data set';
RUN;

proc corr data=co_vary NOSIMPLE;


var IQ SCORE;
run;

proc ttest data=co_vary;


class GROUP;
var IQ SCORE;
run;

proc glm data=co_vary;


class GROUP;
model SCORE = IQ GROUP IQ*GROUP / ss3;
run;

proc glm data=co_vary;


class GROUP;
about:blank 2/3
4/11/25, 10:04 AM Code: Homework 29.sas
model SCORE = IQ GROUP / ss3;
lsmeans GROUP /;
RUN;
quit;

about:blank 3/3

You might also like