Help using Base SAS procedures

2-sample z test

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 138
Accepted Solution

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

View solution in original post


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.

Trusted Advisor
Posts: 1,607

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.

Solution
‎01-16-2014 01:46 PM
Respected Advisor
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);
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

Trusted Advisor
Posts: 1,607

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 ...

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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