SAS Procedures

Help using Base SAS procedures
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Walternate
Obsidian | Level 7

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!

1 ACCEPTED SOLUTION

Accepted Solutions
SteveDenham
Jade | Level 19

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

4 REPLIES 4
ping
Fluorite | Level 6

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.

PaigeMiller
Diamond | Level 26

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
SteveDenham
Jade | Level 19

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

PaigeMiller
Diamond | Level 26

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

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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