Programming the statistical procedures from SAS

paired t-test

Reply
Occasional Contributor
Posts: 7

paired t-test

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      

Super User
Posts: 18,549

Re: paired t-test

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;

Occasional Contributor
Posts: 7

Re: paired t-test

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:

Super User
Posts: 18,549

Re: paired t-test

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;

Trusted Advisor
Posts: 1,221

Re: paired t-test

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;

Occasional Contributor
Posts: 7

Re: paired t-test

But that would not allow me to use a paired t-test. 

Super User
Posts: 9,769

Re: paired t-test

and also you can use     dif=End-Start   to eliminate their correlation , then use proc ttest   H0 : dif=0

Xia Keshan

Super User
Posts: 18,549

Re: paired t-test

Except s/he has the items in different rows so not quite, would still need a transpose.

Super User
Posts: 9,769

Re: paired t-test

Yes. the data should be transposed firstly.

Ask a Question
Discussion stats
  • 8 replies
  • 554 views
  • 3 likes
  • 4 in conversation