BookmarkSubscribeRSS Feed
Songchan
Calcite | Level 5

Hi Guys,

 

I have two columns of observations, and the numbers of observations are different, what I want to do is to test whether the difference between their average value are different from zero, (using t test) how could i do it?

For example,

a        b

1        3

2        7 

3        8

8        6

5       10

9         8

10

15

1

7

9 REPLIES 9
PGStats
Opal | Level 21

Change your data organisation to

 

group value

a        1

b        3

a        2

b        7

... etc

 

and call proc ttest with group as the class variable and value as the var variable.

PG
Songchan
Calcite | Level 5

Hi,

 

data cc01a; set temp03; keep wml; run;
data cc01b; set btemp03; keep wml1;run;
data cc01; merge cc01a cc01b; run;
data cc02; set cc01;
     diff_wml=wml-wml1;
run;

proc means data=cc02 n mean t probt;
     var diff_wml;
	 output out=cc03 n=size mean=m t=tval probt=pvalue;
run;

I did in this way, but the final result for diff_wml was different from the difference between (average wml - average wml1)

 

Songchan

PaigeMiller
Diamond | Level 26

As stated by @PGStats , you need to re-organize the data as he suggested and then use PROC TTEST.

 

PROC MEANS will not produce the result you want in this case.

--
Paige Miller
Songchan
Calcite | Level 5

Hi,

 

Thank you for your reply. But how could I reorganize the data in that way.

 

SC.

Patrick
Opal | Level 21

@Songchan 

Exactly as @PGStats proposes.

data have;
  input a b;
  datalines;
1 3
2 7 
;
run;

data reorg(keep=group value);
  set have;
  group='a';
  value=a;
  output;
  group='b';
  value=b;
  output;
run;
Songchan
Calcite | Level 5

Hi,

 

Thank you!!!

 

If I have a lot of observations in each column, what I need to do?

Patrick
Opal | Level 21

@Songchan 

"what I need to do"

You need to post representative sample data so we can understand what you're dealing with.

Post sample data in the form of a "data have" step as I've done and then show us how the desired result should look like.

 

"If I have a lot of observations in each column"

A table has rows (observations) and columns (variables). For this reason your statement doesn't make sense.

Songchan
Calcite | Level 5

HI,

 

this is what my data looks like, i need to test whether (average wml - average wml1) is different from zero.

Reeza
Super User

You need to append your datasets. 

This assumes your input data set name is HAVE, and your variable names are Var1, var2. 

You may need to add parenthesis to the Keep variable list. 

 

Data want;
Set have (in=a keep=var1)
      Have (in=b drop=var1 rename=var2=var1);

If a then group=‘A’;
Else group=‘B’;
Run;

@Songchan wrote:

HI,

 

this is what my data looks like, i need to test whether (average wml - average wml1) is different from zero.


 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1881 views
  • 0 likes
  • 5 in conversation