- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
But that would not allow me to use a paired t-test.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
and also you can use dif=End-Start to eliminate their correlation , then use proc ttest H0 : dif=0
Xia Keshan
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Except s/he has the items in different rows so not quite, would still need a transpose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes. the data should be transposed firstly.