BookmarkSubscribeRSS Feed
niloo
Obsidian | Level 7

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
15 REPLIES 15
Reeza
Super User

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.

niloo
Obsidian | Level 7

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

Reeza
Super User
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.
Ksharp
Super User

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;

 

niloo
Obsidian | Level 7

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

Reeza
Super User

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.

niloo
Obsidian | Level 7

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

Reeza
Super User

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

 

 

Ksharp
Super User

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.

niloo
Obsidian | Level 7

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

Ksharp
Super User

From the output ,

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

 

lvm
Rhodochrosite | Level 12 lvm
Rhodochrosite | Level 12

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.

niloo
Obsidian | Level 7

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

niloo
Obsidian | Level 7

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 15 replies
  • 5907 views
  • 3 likes
  • 4 in conversation