rankcorr.sas

/************************************************************************************************** ** PROGRAM: rankcorr.sas ** ** PURPOSE: This program calculates: ** 1. Point estimate of Spearman rank correlation and its confidence interval ** 2. Point estimate of Rank correlation given by Kendall"s tau and its confidence ** interval ** ** REQUIREMENT: A ASCII data with three variables: ** 1. id ** 2. x ** 3. y ** ** MACRO VARIABLES: ** 1. Name of the ASCII data set. ** ** USAGE: Enter "%rankcorr(data=) ** ***************************************************************************************************/ %macro rankcorr(data=); options nosource nodate formdlim=' ' nonumber; filename datain "&data"; data _N_; infile datain end=eof; input id h hstar; h=x; hstar=y; if h ne . and hstar ne .; retain n 0; n=n+1; if eof then call symput("n",trim(left(n))); proc rank out=rank; var h hstar; ranks rh rhstar; run; data posa; set rank end=eof; hhat=probit(rh/(&n+1)); hhstar=probit(rhstar/(&n+1)); one=1; run; proc corr pearson data=posa outp=corr noprint; var hhat hhstar; run; data corr; set corr; %let pi=3.1415926; %let title1=%str( ); if _TYPE_='CORR' and _NAME_='hhat'; r=hhstar; rcor=r*(1+(1-r**2)/(2*(&n-4))); psa=6/&pi*arsin(rcor/2); zhat=0.5*log((1+rcor)/(1-rcor)); z1=zhat-1.96/sqrt(&n-3); z2=zhat+1.96/sqrt(&n-3); r1=(exp(2*z1)-1)/(exp(2*z1)+1); r2=(exp(2*z2)-1)/(exp(2*z2)+1); rs1=6/&pi*arsin(r1/2); rs2=6/&pi*arsin(r2/2); taua=(2/&pi)*arsin(rcor); tau1a=(2/&pi)*arsin(r1); tau2a=(2/&pi)*arsin(r2); label psa='Point estimate of Spearman rank correlation'; label r1 ='Lower bound'; label r2 ='Upper bound'; label taua='Rank correlation given by Kendall"s tau'; label tau1a='Lower bound'; label tau2a='Upper bound'; title; proc print label noobs; var psa; run; proc print label noobs; &title1; title2 '95%CI of Spearman rank correlation'; var r1 r2; run; proc print label noobs; var taua; &title1; title2 ' '; run; proc print label noobs; &title1; title2 '95%CI of Rank correlation given by Kendall"s tau'; var tau1a tau2a; run; %mend; %*rankcorr(data=samp.dat);