Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- two sample t-test

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 02-28-2016 04:56 PM
(4520 views)

Hi,

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

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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?

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?

Thank you,

Niloo

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

From the output ,

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

**Available on demand!**

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

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.