I am trying to program the given information for a paired t-test. How would I go about doing this using an array? The information I am trying to read in is:
DATA exam;
input id $ s1-4;
DATALINES;
Start 30 15 20 45
End 35 16 25 42
;
RUN:
below is the general information - we have 4 subjects with a starting grade and an ending grade. I would like to perform a paired t-test.
Subject 1 2 3 4
Start 30 15 20 45
End 35 16 25 12
Sample size is too small to draw any conclusions from this data.
The data is not in the correct format for a SAS test, it would have to be formatted differently. If you have only the four obs that's easy enough to change though:
data paired_example;
input subject start end @@;
datalines;
1 30 35 2 15 16 3 20 25 4 45 12
;
run;
proc ttest data=paired_example;
paired end*start;
run;
I understand that it is a small sample size (I am just using a small sample size b/c I did not want to input the large sample size I truly have). I know it would be easy to complete this just changing the input and datalines, but I do not want to do that. I really want to read in the original datalines (exactly as it is) and use an array so I can eventually use proc ttest. How would I read in the original data and use an array so I can eventually use proc ttest?
DATA exam;
input id $ s1-4;
DATALINES;
Start 30 15 20 45
End 35 16 25 42
;
RUN:
You can't use an array with the t-test unless you want to manually calculate the t-test. You will have to transform your data, to the type that the proc expects it and you can do that via proc transpose. You had some typos in your sample data which are corrected below.
DATA exam;
input id $ s1-s4;
DATALINES;
Start 30 15 20 45
End 35 16 25 42
;
RUN;
proc transpose data=exam out=paired_example;
id id;
run;
proc ttest data=paired_example;
paired end*start;
run;
data want(keep=id s);
set exam;
array st{*} s1-s4;
do i=1 to dim(st);
s=st{i};
output;
end;
run;
proc ttest data=want;
class id;
var s;
run;
But that would not allow me to use a paired t-test.
and also you can use dif=End-Start to eliminate their correlation , then use proc ttest H0 : dif=0
Xia Keshan
Except s/he has the items in different rows so not quite, would still need a transpose.
Yes. the data should be transposed firstly.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.