turn on suggestions

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

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- 2-sample z test

Topic Options

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

01-16-2014 09:11 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Walternate

01-16-2014 01:46 PM

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);

paired_z_pval_twotail=2*(1-cdf('NORMAL',abs(zval))); /* Not so sure about this one, but it works for 1.96 and -1.96 */

run;

Steve Denham

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Walternate

01-16-2014 01:25 PM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Walternate

01-16-2014 01:44 PM

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

Paige Miller

Solution

01-16-2014
01:46 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Walternate

01-16-2014 01:46 PM

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);

paired_z_pval_twotail=2*(1-cdf('NORMAL',abs(zval))); /* Not so sure about this one, but it works for 1.96 and -1.96 */

run;

Steve Denham

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to SteveDenham

01-16-2014 01:58 PM

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

Paige Miller