BookmarkSubscribeRSS Feed
Bailey
Calcite | Level 5

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      

8 REPLIES 8
Reeza
Super User

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;

Bailey
Calcite | Level 5

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:

Reeza
Super User

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;

stat_sas
Ammonite | Level 13

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;

Bailey
Calcite | Level 5

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

Ksharp
Super User

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

Xia Keshan

Reeza
Super User

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

Ksharp
Super User

Yes. the data should be transposed firstly.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

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.

Discussion stats
  • 8 replies
  • 2281 views
  • 3 likes
  • 4 in conversation