## 2-sample z test

Solved
Frequent Contributor
Posts: 138

# 2-sample z test

Hi,

Could someone please tell me how to run a paired sample z test in SAS? I can't find the code anywhere.

My data consists of a population with a measure taken at two time points, so:

Person     var1       var2

A             35          58

B             54          55

C             49          43

I know a t test is easier, but I have been requested to do a z test.

Any help is much appreciated!

Accepted Solutions
Solution
‎01-16-2014 01:46 PM
Posts: 2,655

## Re: 2-sample z test

I would argue that you should kind of dig in your heels and insist on the paired t test.  However, if you find the difference between var1 and var2, and use PROC UNIVARIATE.

data one;/* Make up some data, where x is a difference between two values */
input x @@;
datalines;
1 3 -2 -5 4 6 -9
;
run;
ods output moments=moments;
proc univariate data=one;
run;

data keep1 keep2;/*Get the mean of the difference and the standard error of the difference*/
set moments;
if Label1='Mean' then output keep1;
if label2='Std Error Mean' then output keep2;
run;

data keep1;
set keep1;
keep varname label1 nvalue1;
run;

data keep2;
set keep2;
keep varname label2 nvalue2;
run;

data test;/* Calculate a z value, and associated probability values */
merge keep1 keep2;
zval=nvalue1/nvalue2;
paired_z_pval_onetail=cdf('NORMAL', zval);
run;

Steve Denham

All Replies
Contributor
Posts: 22

## Re: 2-sample z test

Just create a variable diff=var1-var2, and then apply PROC UNIVARIATE to the new variable. I think if sample size is small, it is preferable to use t-test.

Posts: 2,979

## Re: 2-sample z test

A z-test requires you to have the population variance, which you haven't stated. If that's really what you want, you could use SAS to compute the means and then plug the means and the population variance into the z-test forumla.

If you want to use a t-test, you could certainly use PROC TTEST; there are examples in the documentation.

--
Paige Miller
Solution
‎01-16-2014 01:46 PM
Posts: 2,655

## Re: 2-sample z test

I would argue that you should kind of dig in your heels and insist on the paired t test.  However, if you find the difference between var1 and var2, and use PROC UNIVARIATE.

data one;/* Make up some data, where x is a difference between two values */
input x @@;
datalines;
1 3 -2 -5 4 6 -9
;
run;
ods output moments=moments;
proc univariate data=one;
run;

data keep1 keep2;/*Get the mean of the difference and the standard error of the difference*/
set moments;
if Label1='Mean' then output keep1;
if label2='Std Error Mean' then output keep2;
run;

data keep1;
set keep1;
keep varname label1 nvalue1;
run;

data keep2;
set keep2;
keep varname label2 nvalue2;
run;

data test;/* Calculate a z value, and associated probability values */
merge keep1 keep2;
zval=nvalue1/nvalue2;
paired_z_pval_onetail=cdf('NORMAL', zval);
run;

Steve Denham

Posts: 2,979

## Re: 2-sample z test

```I would argue that you should kind of dig in your heels and insist on the paired t test.
```

I would argue that too, unless it is a homework assignment ...

--
Paige Miller
🔒 This topic is solved and locked.

Discussion stats
• 4 replies
• 4098 views
• 6 likes
• 4 in conversation