Programming the statistical procedures from SAS

two sample t-test

Reply
Contributor
Posts: 51

two sample t-test

Hi,

 

I have 5 numerical variables and I am trying to run a t-test to figure out if the variables are equal.

ttest.png

I tried to use the following t-test statement:
 
proc ttest data=econttest ;
  title "Two sample t-test Econ";
  class zero; 
var one;
   run;
 
But I received the following error: ERROR: The CLASS variable has more than two levels.
So, I used a proc GLM as follows: 
   proc glm data=Econttest;
class zero;
model one = zero;
lsmeans zero / pdiff;
run;
 
Would you please let me know if I am using the right statements? If not which statement shoild I use?
I have attached my output.
 
Thank you,
Niloo
Super User
Posts: 18,479

Re: two sample t-test

Have you changed your data format or maintained that format in SAS, ie one column per variable?

 

If so, then your data is not structured to facilitate the comparison in SAS, so your code and results are incorrect. 

 

Change your data so that you have a variable that identifies the Variable and another that holds the value. 

Proc Transpose can be used to transform your data.

Contributor
Posts: 51

Re: two sample t-test

Dear Reeza,

 

Thank you for your response. I have not changes my data format. I did some research on proc transpose, is this how I can use it?

proc transpose data=econttest out=econttest1;
  by zero;
run;

 I am trying to find out if variable zero=one, one=two, two=three, three=four.

 

Thanks,

Niloo

Super User
Posts: 18,479

Re: two sample t-test

I don't know. Does your data look correct afterward? I doubt it, since zero doesn't appear to be a grouping variable.

Google SAS UCLA WIDE TO LONG and you'll find examples of transposing using proc transpose or a data step.

Also, if your doing mutiple t-tests its worth looking into PROC MULTTEST.
Super User
Posts: 9,753

Re: two sample t-test

[ Edited ]

You need change your data structure ,like :

 

data temp;

 set have;

 array x{*} zero one two three four;

length group $ 20;

do i=1 to dim(x);

 group=vname(x{i});

 value=x{i};

 output;

end;

run;

 

/* Since your design is balanced , you can use proc anova to test */

proc anova data=have;

class group;
model value=group;
mean group/ scheffe;
run;

 

Contributor
Posts: 51

Re: two sample t-test

Dear Xia,

 

Thank you for your help. I used your codes and got the attached output. Does this table mean that non of the comparisons is significant?

 

Anova.png

 

Can I conclude that the none of the differences between the variables (zero, one, two, three, four) are equal?or all the H0: μ1=μ2 are rejected?

anova1.png

 Thank you,

Niloo

Super User
Posts: 18,479

Re: two sample t-test

From the ANOVA the p-value is 0.019, less than 0.05, therefore you reject your null hypothesis.  

 

However, your pairwise comparisons show no difference, where the level of significance has been corrected for multiple testing. 

 

You didn't post your code so I can't say anything beyond this.

Contributor
Posts: 51

Re: two sample t-test

Hi Reeza,

 

Here is the code:

data econttest;
set work.econ;
run;


data econ1;
set econttest;
array x{*} zero one two three four;
length group $ 20;
do i=1 to dim(x);
group=vname(x{i});
value=x{i};
output;
end;
run;

proc anova data=econ1;
class group;
model value=group;
mean group/ scheffe;
run;

 

Thanks

Niloo

Super User
Posts: 18,479

Re: two sample t-test

Thanks, your code doesn't change my answer. 

The ANOVA shows a significant difference. 

The pairwise tests do not. 

 

Why -> 

http://www.graphpad.com/guides/prism/6/statistics/index.htm?stat_results_post_tests_2.htm

 

 

Super User
Posts: 9,753

Re: two sample t-test

From your output :

Number of Observations Read 805

Number of Observations Used 444

 

I doubted it is not balance design. So proc anova is not trusted.

Switch into PROC GLM + mean or lsmean . as Reeza suggested.

Contributor
Posts: 51

Re: two sample t-test

Hi,

I am using the following the following statements but the results (attached) look funny:

 

data econ1;
set econttest;
array x{*} zero one two three four;
length group $ 20;
do i=1 to dim(x);
group=vname(x{i});
value=x{i};
output;
end;
run;


proc glm data=Econ1;
class zero;
model one = zero;
lsmeans zero / pdiff;
run;

Could you please tell me how I can fix my code?

 

Thanks,

Niloo

Super User
Posts: 9,753

Re: two sample t-test

From the output ,

Simultaneous 95% Confidence Limits   all contains zero . so it is hard to say which group is different another group.

 

Valued Guide
Valued Guide
Posts: 684

Re: two sample t-test

You should not be using the Scheffe adjustment option. This is way too conservative. Change to Tukey, or see what happens without the option at all.

Contributor
Posts: 51

Re: two sample t-test

Hi,

 

I ran the Proc GLM without the adjustment and the results still look funny(attached pdf is the output) 

data econ;
set work.econ;
run;

proc glm data=Econ;
class zero;
model one = zero;
lsmeans zero / pdiff;
run;

 

Tahnks, 

Niloo

Contributor
Posts: 51

Re: two sample t-test

Hi again,

 

I went through my data and I think I have to use a paired t-test since each row in my data is related to one company. I used the following statements: 

proc ttest data=econ sides=2 alpha=0.05 h0=0;
title "Paired sample t-test example";
paired zero * one;
run;

My output does not look funny anymore. Could you please chekc out my output (attached)and let me know if I have got it right this time?

 

Thank you very much,

Niloo

Ask a Question
Discussion stats
  • 15 replies
  • 1179 views
  • 3 likes
  • 4 in conversation