- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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